Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script help

Status
Not open for further replies.

rockies

MIS
Sep 24, 2001
25
US
How i can add the script that shows
system is ready when machine reboot.
if system is ready then starts another script (sys_backup)

if any one help me on this ..or any idea wellcome


rockies
mmpatel345@yahoo.com
 
You could put your sys_backup script (or a link to it) in /etc/rc3.d and call it something like S99sys_backup. This will then only kick in once the other processes in the startup procedure have completed and the system is effectively up. HTH.
 
Thankyou so much.
I donot know how to make the link or call.
can you pls give me idea of that . Also one query

If i follow Like that then if any emergency reboot / or any maintenance reboot /shutdown is done then sysbackup would run. that is not good.

I want to Add in crontab file . how i can do it ??
Rightnow in crontab file there is schedule reboot script
as well as sysbackup script which runs at 3 and 5 o'clock.
i wana add some thing that way once machine is up /system is ready then starts sysbackup..automatically.
i think you got idea what i mention. if not let me know i will give more Information.
Thanks a lot for your help.
rockies
mmpatel345@yahoo.com
 
Pleased to help. As far as the first question is concerned, it is normal practice to put a copy of your script (sys_backup or whatever) in the directory /etc/init.d

You then create a link from /etc/init.d to /etc/rc3.d as follows:

ln /etc/init.d/sys_backup /etc/rc3.d/S99sys_backup

This creates a virtual copy of your sys_backup file in the /etc/rc3.d directory.

You are quite correct in your assumption that in these circumstances the backup script would run following an emergency reboot or power outage. I'll need to have a think about your crontab requirement (it's getting late here!), but it's entirely possible that someone else might be able to help you whilst I'm in the land of Nod!
 
The crontab file can erase a flag type file when it reboots. After the reboot the rc3.d startup script can look for this flag/file and do a backup if it is not detected. Otherwise the startup script does nothing. At the end of performing a backup, the startup script can set the flag/file.
 
Thanks to Bluedevils ,KenCunningham for help.
Bluedevils,
Can you tell me how i can modify it.
i donot know how it works . If you tell something I can Test
on test server
Thanks.

rockies
mmpatel345@yahoo.com
 
I have never done this so here's another version that might work.

1)make a template file with the backup commandline (the same command in your etc/init.d/sys_backup)

2)just before the cronjob does a reboot it can copy the backup command into the flag/file. "cat backup.template > backup.flag"

3)In the startup script you can have lines like &quot;/<path>/backup.flag&quot; and &quot;cp /dev/null /<path>/backup.flag&quot; This will run the backup and then empty the file. The next time when there is an unscheduled reboot, there will not be a command to execute in the backup.flag file.
 
Thanks . Let me try i will get back with result.
If any one had suggestion feel free to say..

rockies
mmpatel345@yahoo.com
 
I was confused on someof the steps. can you have more details for implementation !!
 
This is the crontab which include schedule reboot and sys_backup
As Below :--

# PCM Scheduled reboot
# every Saturday
0 3 * * 6 [ -x /usr/local/bin/shutdown ] && /usr/local/bin/shutdown > /dev/console 2>&1
#
# Alternate root/usr backups.
# every Saturday
0 5 * * 6 [ -x /usr/local/bin/sys_backup ] && /usr/local/bin/sys_backup > /tmp/backup.log 2>&1; cp /tmp/backup.log /usr/adm/sys_backup.log

what modification i have to do as per bluedevils !!
please guide me !

Thanks a Lot.
 
If my understanding is correct, kind of what bluedevils meant was to edit your shutdown cron script to include writing a 'flag' file when it begins to shutdown. This will place a file wherever you like which can then be tested for existence by a script in rc3.d when the system comes back up. If the file exists, it is clear that the system shutdown was as a result of the normal cron job, rather than an unscheduled halt, and the same script could then kick off the backup.

The backup script would need to be amended to include provision to delete the flag file once it is finished. If the system goes down as a result of an unscheduled halt, the flag file wouldn't exist and the startup script should be such that in this event the backup would not be kicked off. Can you post your shutdown and backup scripts if you require further advice, please? Hope this helps.
 
Sorry Rockies, my last post obviously crossed with yours. What I meant was to post the scripts:

/usr/local/bin/shutdown and /usr/local/bin/sys_backup.

Please feel free to amend these if they contain any propriety information or whatever - just the bare bones should do. Cheers.
 
send me your email so i can forward it to you.
that both script . b'cos it's big .

what steps need to be added in that let me know .

 
KenCunningham , are you there !!
send me your email so i can ..
 
#For something like this you might want to make a script file. The cronjob is too involved.

0 3 * * 6 /usr/local/bin/My_Scheduled_Reboot


#The script file (My_Scheduled_Reboot)

cp /<path>/sys_backup.template /<path>/sys_backup.flag
init 6


#template file (sys_backup.template)

/usr/local/bin/sys_backup && /usr/local/bin/sys_backup > /tmp/backup.log 2>&1; cp /tmp/backup.log /usr/adm/sys_backup.log


#/etc/init.d/sys_backup (the source to a link like /etc/rc3.d/S99sys_backup)

/<path>/sys_backup.flag
 
my shutdown script looks like this as below. what will happen to this ..you know i mean..!!!


#!/bin/ksh
#
MSG=${1:-&quot;PCM Scheduled Reboot&quot;}
tty -s && (echo &quot;${MSG}&quot;; \w)
logger -p cron.notice &quot;${MSG}&quot;

case &quot;`/bin/uname -sr | /bin/sed -e 's/ //g' -e 's/\..*//'`&quot; in
SunOS4)
STATE=${2:-&quot;r&quot;}
/usr/local/bin/uptime.down +5 +30 &quot;${MSG}&quot;
exec /usr/etc/shutdown -${STATE} +5 &quot;${MSG}&quot; >/dev/console 2>&1
;;
SunOS5)
STATE=${2:-&quot;6&quot;}
/usr/local/bin/uptime.down +5 +30 &quot;${MSG}&quot;
exec /usr/sbin/shutdown -i${STATE} -y -g300 &quot;${MSG}&quot; >/dev/console 2>&1
;;
HP*)
STATE=${2:-&quot;r&quot;}
/usr/local/bin/uptime.down +5 +30 &quot;${MSG}&quot;
exec /etc/shutdown -${STATE} -y 300 >/dev/console 2>&1
;;
SMP_DC*)
STATE=${2:-&quot;6&quot;}
/usr/local/bin/uptime.down +5 +45 &quot;${MSG}&quot;
exec /sbin/shutdown -i${STATE} -y -g300 >/dev/console 2>&1
;;
*)
echo &quot;Dont know how to halt/reboot OS=$OS&quot;
exit 1
;;
esac
 
How i can modify this...so that it works with our shutown script !!!! you know what i mean ! (script is as above which does uptime also)

0 3 * * 6 /usr/local/bin/My_Scheduled_Reboot


#The script file (My_Scheduled_Reboot)

cp /<path>/sys_backup.template /<path>/sys_backup.flag
init 6
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top