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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

expr on script

Status
Not open for further replies.

visvid

Technical User
Jun 3, 2002
131
GB
I have 2 scripts which I want to add to the cron , but I have to push these out to 65 nodes , I also need to ensure that the time is different on each node , rather than editing the cron on each node can anyone help with a script I can send out from the workstation

The scripts are

# Script to run a monthly config build and ftp it to drftp
01 5 1 * * /config/dr-build >/dev/null 2>&1
30 5 1 * * /config/dr-check >/dev/null 2>&1

On each node I need a 5 minute change in the start times

guess theses 2 lines would be appended to the bottom off var/spool/cron/crontabs/root rather than trying to do a crontab –e in a script

If you append the bottom of a crontab do I need to refresh cron ? These are AIX servers

cheers


On the 7th day God created Super Moto
:)
 
Here is a prototype, not tested the 'scp' - section.
Don't know whether scp has an append-option.
Only using one comand.
It only shows how to use an array to access different names in a loop, and how to calculate. $(($x+5))

Code:
#!/bin/bash
#
#
CMD1="* * /config/dr-build >/dev/null 2>&1"
#
ADR=("root@server" "root@plutonium" "root@backup")
min=0
hour=0
for (( i = 0; i < 3; ++i)) ; do
	min=$(($min+5))
	if (( min >= 60 )); then
		min=$(($min-60))
		hour=$(($hour+1))
		if (( hour >= 24 )); then
			hour=$(($hour-24))
		fi
	fi
	echo $min $hour 1 $CMD1 > cronappend.snipplet
	scp --append cronappend.snipplet ${ADR[${i}]}/var/spool/crontabs/root
done

seeking a job as java-programmer in Berlin:
 
cheers stefan i will test this out today , do you know if I have to refresh the crontab ?

On the 7th day God created Super Moto
:)
 
If you append to the bottom of the relevant crontab, you should refresh it using crontab <filename>. It's best to edit a working copy of the crontab and then refresh it with that, in case of typos etc which can cause havoc. At least you then have the working one to fall back on. Regards.
 
I wish I could that far , we work in ksh and i am having probs with (( etc , not sure the scp --append cmd works as i cant see anything on man pages , we are AIX 5.2 so maybe a straight scp ???

I am not a script person so bebugging is a mare for me :-(

On the 7th day God created Super Moto
:)
 
!/bin/ksh
set -x
#
#
CMD1="/config/dr-build >/dev/null 2>&1"
#CMD2="/config/dr-check >/dev/null 2>&1"

min=0
hour=5
for i in `cat /tmp/node_list`
do
min=`expr $min + 5`
if [[ $min = 60 ]]; then
min=0

hour=`expr $hour +1`
fi
ssh $i 'echo "$min $hour * 1 * $CMD1\n" >> /tmp/simon'

done

Now the problem is i only get * 1 * at the bottom of my file , instead of the whole cron entry any ideas

On the 7th day God created Super Moto
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top