Operating System - HP-UX
1836528 Members
3780 Online
110101 Solutions
New Discussion

how to pass arguments to the script with at command

 
SOLVED
Go to solution
Aji Thomas
Regular Advisor

how to pass arguments to the script with at command

hi guys,

I am trying to write a backup script to back up my oracle datafiles and I am trying to pass an argument while executing the script.
eg: sh back_script 2

Now within my script i have specified
cp /home/oracle/example.dbf /home/day$1

Based on the input argument the backup goes to the directory /home/day2.

but when i need to schedule the backup using the at command, i am unable to pass an argument. It says bad date specification.
How best can I achieve my objective.
AJI

9 REPLIES 9
Doug O'Leary
Honored Contributor

Re: how to pass arguments to the script with at command

Hey;

A couple of things to try. First, if you're doing this from the command line, then enter:

at ${time_string}
/bin/sh /path_to_script/back_script 2 &
D

Another thing you should consider is using cron instead of at. More often than not, you want backup scripts to run periodically, not just once. To do that, execute crontab -e, then enter:

${min} ${hour} ${day} ${month} ${weekday} /path_to_script/back_script 2 > /dev/null 2>&1

If you really need to run this all from a single command line using at, put the commmand entire command in quotes:

at ${time_string} "sh back_script 2"

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Aji Thomas
Regular Advisor

Re: how to pass arguments to the script with at command

Hi Doug,

Thanks for the reply,
but I will be executing another file "startbackup" where i want to specify something like
at -f backupscript 2 16:45

This 2 has to be passed to backupscript.
Please advice me
AJI
Ermin Borovac
Honored Contributor
Solution

Re: how to pass arguments to the script with at command

Argument to -f option must be name of the file containing commands.

You can try

# echo "sh backupscript 2" | at 16:45
Aji Thomas
Regular Advisor

Re: how to pass arguments to the script with at command

Hi Ermin Borovac ,

the command exactly work the way i want from command line.
But you know I want something like
echo "sh backupscript $1" | at 17:51

where $1 is parameter i specify when i run the script like
$ sh startbackup 2

this value 2 should come in the syntax specified by you

thanks in advance
AJI
Mel Burslan
Honored Contributor

Re: how to pass arguments to the script with at command

chmod o+x backupscript # these lines will eliminate need for sh directive
chmod o+x startbackup

your startbackup script will have a line like this:

at 17:51 /path/to/script/backupscript $1


you invoke your startbackup

/path/to/script/startbackup 2

hope this helps
________________________________
UNIX because I majored in cryptology...
Aji Thomas
Regular Advisor

Re: how to pass arguments to the script with at command

HI mel

I tried this way before, and tried exactly following the way specified by you again, but i am getting bad date specification error.

please advice me,
AJI

Victor Fridyev
Honored Contributor

Re: how to pass arguments to the script with at command

Hi,

Try this:
echo "sh back_script 2" | at now + 1 minutes

HTH
Entities are not to be multiplied beyond necessity - RTFM
Mel Burslan
Honored Contributor

Re: how to pass arguments to the script with at command

okay, there is something deeper going on in here. $1 in this directive is not a date specification, 17:51 is. If it is not working, could you please copy & paste, or attach the script/scripts and tell us how you start them, i.e., if it is from the command line, show us the command, or if it is from cron, paster the cron entry line from the crontab.

Without those, we are fighting with an enemy that we can not see with our hands tied on our backs. Unfortunately, there is no single solution to any particular problem in unix and there is no blanket solution to a generalized statement. I have learnt this if nothing else in my 15+ years of being a sysadmin.

Please provide as much detail as possible.
________________________________
UNIX because I majored in cryptology...
Aji Thomas
Regular Advisor

Re: how to pass arguments to the script with at command

hi

It started working by modifying startscript
as
echo "sh backupscript $1" | at 17:51

and now i can run as
$./startscript 2

thanks guys for the support