Tag Archives: HOSTNAME

How to exit a script with error ?

By Salil Gupta

Hi,

I have a script ABC which calls another script XYZ. Function of XYZ is to ftp a file from one server to another.

code for ABC:

Code:

#!/bin/ksh
PATH=/usr/bin

home/user/xyz "$@"

exit $?
~


code for xyz:

Code:

#!/bin/ksh
HOSTNAME=$1
SRCNAME=$2
DSTNAME=$3

### This file holds the outget of the FTP commands for success checking
FTPCHK=/tmp/ftpchk.$$
#touch $FTPCHK
echo "" > $FTPCHK

SRCFILE=$SRCNAME

DSTFILE=$DSTNAME

echo Source Host: $HOSTNAME
echo Source File Name: $SRCFILE
echo Destination File: $DSTFILE

echo `date` Beginning FTP download...
ftp -v ${HOSTNAME} <>$FTPCHK 2>&1
ascii
nlist ${SRCFILE}
get ${SRCFILE} ${DSTFILE}
quit
EOF

### Check for FTP errors
CHK1=`grep -c "226 Transfer complete." $FTPCHK`
CHK2=`grep -c "226 ASCII Transfer complete." $FTPCHK`
CHK3=`grep -ic "226 transfer complete" $FTPCHK`
CHK4=`grep -ic "226 File send OK." $FTPCHK`

### In NT, There should transmissions complete:
### One for the data transfer,
### One for the nlist

if [ $CHK1 -eq 2 ] || [ $CHK2 -eq 2 ] || [ $CHK1 -eq 1 -a $CHK2 -eq 1 ] || [ $CHK3 -eq 2 ] || [ $CHK4 -eq 1 ]; then
RC=0
echo "OK: FTP Transmission Worked"
echo '--------------------------------------------------------------'
cat $FTPCHK
echo '--------------------------------------------------------------'

else
RC=1
echo "ERROR: FTP Transmission Failed"
banner "ERROR"
echo '--------------------------------------------------------------'
cat $FTPCHK
echo '--------------------------------------------------------------'
fi

date
ls -al ${DSTFILE}

rm $FTPCHK

echo '---------------------------------------------------------------------'

exit $RC


In script XYZ, I am trying to ftp a file. So during ftp , whenever it shows that space is less than size of file, it should ftp the partial according to the available space and prompt a message about it and also prompt a message to outer script that inner script could not complete successfully. Hence resulting in the failure of outer script, due to partial ftp of file.

Also please post the comments about the each step of script to explain what is happening in that step. Thanks a lot in advance.

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

How to set up newgrp on .profile?

By Pateltiger

Hello all,

I am having an issue setting up an environment on .profile. I want to set up my .profile in that way that everytime I login to the host, it should automatically set up my group. I tried the folllowing but it doesn’t work. It is on the solaris OS.

HOSTNAME=$(hostname)

if [[ “$HOSTNAME” = “tpat1a” ]] || [[ “$HOSTNAME” = “tpat2a” ]]
then
newgrp unixteam
umask 002
fi

Any help will be appreciated.

Thanks
PT

Hello all,

I am having an issue setting up an environment on .profile. I want to set up my .profile in that way that everytime I login to the host, it should automatically set up my group. I tried the folllowing but it doesn’t work. It is on the solaris OS.

HOSTNAME=$(hostname)

if [[ “$HOSTNAME” = “tpat1a” ]] || [[ “$HOSTNAME” = “tpat2a” ]]
then
newgrp unixteam
umask 002
fi

Any help will be appreciated.

Thanks
PT

Hi Gurus,

I am having an issue setting up an environment on .profile. I want to set up my .profile in that way that everytime I login to the host, it should automatically set up my group. I tried the folllowing but it doesn’t work. It is on the solaris OS.

HOSTNAME=$(hostname)

if [[ “$HOSTNAME” = “tpat1a” ]] || [[ “$HOSTNAME” = “tpat2a” ]]
then
newgrp unixteam
umask 002
fi

Any help will be appreciated.

Thanks
PT

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Help in printing n number of lines if a search string matches in a file

By neha0785

Hi
I have below script which is used to grep specific errors and if error string matches send an email alert.
Script is working fine , however , i wish to print next 10 lines of the string match to get the details of error in the email alert

Current code:-

#!/bin/bash
tail -Fn0 –retry /tmp/error.log |
while read line ; do
echo “$line” | egrep “java.lang.NullPointerException|java.lang.IllegalStateException|java.sql.SQLException”
if [[ $? = 0 ]] ;
then
HOSTNAME=abc.com
SUBJECT=”Error in “$HOSTNAME” Reported”
MESSAGE=”/tmp/message.txt”
TO=”name@xyz.com”
echo “$line” > $MESSAGE
/bin/mail -s “$SUBJECT” “$TO” < $MESSAGE
fi
done

Appreciate any inputs.
I wish to keep the changes to code as minimal as possible.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Find and replace using sed command

By kmanivan82

The content of the file filea.txt is as follows.
———
case $HOSTNAME in
aaa)
DS_PARM_VALUE_SET=vsDev
APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt

;;
bbb)
DS_PARM_VALUE_SET=vsQA
APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt

;;
ccc)
DS_PARM_VALUE_SET=vsProd
APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt

;;
*)
DS_PARM_VALUE_SET=vsDev
APT_Configurations_File=/appl/infoserver/Server/Configuarations/2node.apt

;;
esac
———

Now aaa has to be changed to ‘DEV’, bbb has to be changed to ‘QA‘ and ccc has to be changed to ‘PROD’.

The new file should be as follows.
———
case $HOSTNAME in
‘DEV’)
DS_PARM_VALUE_SET=vsDev
APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt

;;
QA‘)
DS_PARM_VALUE_SET=vsQA
APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt

;;
‘PROD’)
DS_PARM_VALUE_SET=vsProd
APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt

;;
*)
…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

How to return a message after command runs?

By newbie2010

I have a script like this:


echo "enter filername in lowercase"
read -e filername exec 2>&1
echo "type the start date in format MM/DD/YYYY"
read -e startdate exec 2>&1
echo "enter the end date in format MM/DD/YYYY"
read -e enddate exec 2>&1
echo "please enter the path of file"
read -e filepath exec 2>&1
[ $(echo $filepath | egrep -c '^/*/.*[/]$') -ne 0 ] && echo " enter path without trailing slash" && read filepath
command=`/local/mnt/script.host.pl -client=$filername -start=$startdate -end=$enddate -show_files -filename=$filepath
|gawk '{print $1, $11}' |grep -v HOSTNAME | grep -vi Totals |uniq`
echo $command; if [[ "$command" == "No" ]]; then echo "yes";fi


…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Merging two text files side by side

By FishTornadoHi everyone,

I need to merge two files side by side

The files look something like this:

Code:
HOSTNAME
fishtornado-K52F 127.0.1.1
UPTIME
20:17:01 up 2:19, 3 users,
load average: 0.00, 0.04, 0.05
DISK USAGE
(Size/Used/Avail/Use%)
29G 6.5G 21G 25%
RUN QUEUE
PID COMMAND USER %CPU %MEM
2035 chromium-browse 1000 3.1 10.8
1955 chromium-browse 1000 1.9 2.5
1708 gnome-shell 1000 1.5 2.5
1195 Xorg root 1.3 0.6
2614 chromium-browse 1000 1.0 1.5
The desirable output would be something similar to this:

Code:
HOSTNAME HOSTNAME
fishtornado-K52F 127.0.1.1 fishtornado-K52F 127.0.1.1
UPTIME UPTIME
21:06:05 up 3:08, 3 users, 21:06:08 up 3:08, 3 users,
load average: 0.05, 0.04, 0.05 load average: 0.05, 0.04, 0.05
DISK USAGE DISK USAGE
(Size/Used/Avail/Use%) (Size/Used/Avail/Use%)
29G 6.5G 21G 25% 29G 6.5G 21G 25%
RUN QUEUE RUN QUEUE
PID COMMAND USER %CPU %MEM PID COMMAND USER %CPU %MEM
2035 chromium-browse 1000 2.5 9.5 2035 chromium-browse 1000 2.5 9.5
1955 chromium-browse 1000 2.3 2.6 1955 chromium-browse 1000 2.3 2.6
4584 chromium-browse 1000 2.2 1.9 4584 chromium-browse 1000 2.2 1.9
1708 gnome-shell 1000 1.6 2.5 1708 gnome-shell 1000 1.6 2.5
1195 Xorg root 1.4 0.6 1195 Xorg root 1.4 0.6
I tried using the paste command and various awk scripts but the rows always came out to be scrambled.

Like this (result of paste):

Code:
HOSTNAME HOSTNAME
fishtornado-K52F 127.0.1.1 fishtornado-K52F 127.0.1.1
UPTIME UPTIME
21:06:05 up 3:08, 3 users, 21:06:08 up 3:08, 3 users,
load average: 0.05, 0.04, 0.05 load average: 0.05, 0.04, 0.05
DISK USAGE DISK USAGE
(Size/Used/Avail/Use%) (Size/Used/Avail/Use%)
29G 6.5G 21G 25% 29G 6.5G 21G 25%
RUN QUEUE RUN QUEUE
PID COMMAND USER %CPU %MEM PID COMMAND USER %CPU %MEM
2035 chromium-browse 1000 2.5 9.5 2035 chromium-browse 1000 2.5 9.5
1955 chromium-browse 1000 2.3 2.6 1955 chromium-browse 1000 2.3 2.6
4584 chromium-browse 1000 2.2 1.9 4584 chromium-browse 1000 2.2 1.9
1708 gnome-shell 1000 1.6 2.5 1708 gnome-shell 1000 1.6 2.5
1195 Xorg root 1.4 0.6 1195 Xorg root 1.4 0.6
Thank you in advance for your help.
Source: The UNIX and Linux Forums