1834157 Members
2261 Online
110064 Solutions
New Discussion

Re: Shell Scripting

 
Ahmed_41
Super Advisor

Shell Scripting

Dear All,

i need to implement the following shell scripts and since i am not that good in scripting so i can explain the idea of the scripts and can someone help me get them done.

first script:
create script to run from the cron tab every 5 min to check on the availability of another machine (ping) and in case the ping is not working then this other machine is not live, so change the IP of the running machine to the IP of the failed machine then set a flag that the backup machine is running, so as you will check on it next time the cron tab is perfomrning the script.


Second Script:

the idea is i need to make a backup from one machine, move it to another machine in a specified location, then perform the unbackup on the other machine.

on one machine, i will do something like backup or copy for some folders and files, then i need to copy or ftp or whatever the way to the other machine, in a specific location on this other machine, then i would unbackup, or if i am doing cpy then no operation will be done, i need to do this also in the cron tab every one day and every one week.



thanks
4 REPLIES 4
Ivajlo Yanakiev
Respected Contributor

Re: Shell Scripting

If you not good in scripting.
read some doc and after that if you can not find way we will tell you :))


read
#man cron
#man bash
Bharat Katkar
Honored Contributor

Re: Shell Scripting

Hi Ahmed,
It is advisable to learn some shell scripting first becuase even if any one gives you the readymade script then also you need to customize it according to your environment and even maintain it further.
To start with you can go thr' korn shell scritping on the link below and once you are familiar with korn then it makes little difference with other shells.

http://www.hk8.org/old_web/unix/ksh/index.htm

Also you can learn perl programming which is the most powerful scripting laguage.

http://www.hk8.org/old_web/perl/learn/index.htm

Hope that helps.
Regards,
You need to know a lot to actually know how little you know
abhijeet_7
Advisor

Re: Shell Scripting

Hi Ahmed,
as far ur first script is concerned,i couldn't get the idea of changing IP..
i use a script to continually check/ping all my machines in LAN...& i have kept it in cron..
scrip name: pingcheck
#! /bin/sh
(first to check whether cron deamon is running or not)
vard=`ps -aef | grep -v grep | grep cron | wc -l`
if [ $vard = 0 ]
then
logger -p daemon.notice "ERROR: Cron Daemon Killed "
fi
(second keep a ping to other hosts)

ping 137.xx.xx.xxx -n 4 >cpr
cat cpr | grep -v 64 | grep -v Statistics | grep "0%" | grep -v "round" >cpr1
var=`cat cpr1 | awk ' { print $4 }'`
if [ $var = 0 ]
then
logger -p user.err "ERROR: Cannot reach 137.xx.xx.xxx(New host Connectivity)"
fi
(check errors in /var/adm/syslog/syslog.log)
u can extend this script for as many hosts in ur LAN.

u can keep this script in cron to check for every 15 mins for 6 working days..
# crontab -l

00,15,30,45 06-23 * * 1-6 /home/ahmed/pingcheck

[of course u can modify ur crontab :)]

------------------------------------------
for the second script:
it can look like this:
scrip name: f3

#! /bin/sh
cd /dumps/dbdump
ls * >/home/ahmed/f3_tmp

##########################################
for file in `cat /home/ahmed/f3_tmp`
do
echo $file
sleep 2
HOST='137.xx.xx.xx'
USER='ahmed' )user name & password are
PASSWD='xxxxxx' )hardcoded
FILE=`echo $file`
ftp -n $HOST <
quote USER $USER
quote PASS $PASSWD
bin
cd /dumps/dbdump
put /dumps/dbdump/$FILE

quit
END_SCRIPT

#exit 0
done

u can keep this script in cron too..

#crontab -l
00 18 * * 1-6 /home/ahmed/f3

hope this helps..if not then don blame me:D
regards

ABHIK
we work, to become...not acquire
Chris Vail
Honored Contributor

Re: Shell Scripting

Ahmed:
Using ping to check the availability of a system is not a good idea. It is too low in the IP stack. It is possible for a system that is completely hosed to still respond to a ping.
Better is to use remsh or secure shell or something else that requires the remote system to actually do something:
remsh DESTHOST "ls -l /etc/hosts"

Your second question can be done with tar and rcp or scp.
cd DIRECTORY
tar cvf /tmp/tarball .
scp (or rcp) /tmp/tarball DESTINATION:DIRECTORY
ssh (or remsh) DESTINATION "tar xvf DIRECTORY/tarball"

Cron is easy to use. Do "man crontab". It'll tell you all you need.


Chris