943,685 Members | Top Members by Rank

Ad:
Feb 3rd, 2005
0

bash:redirecting stdin to at command

Expand Post »
Looking to figure out how to do set an at job up from within a shell script w/o using the -f option.

The at -f option provides no method (that I can determine) for passing additional command line parameters to the file.

I have explored trying to use stdin redirection to bypass the interactive
1 command per line , using stuff like the following:

at now +3 days << /path/scriptname -foo -bar

This fails w/ garbled time error, I then tried to simulate the newline, CTRL-D
used w/ the interactive stdin;

at now +3 days << /path/script -foo -bar $'\n' $'\x04'

Nothing yet has produced the desired results.

Thanks in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
flying is offline Offline
1 posts
since Feb 2005
Feb 11th, 2005
0

Re: bash:redirecting stdin to at command

If i understand what your trying to do try atrm

I just attempted this as a small test

Shell Scripting Syntax (Toggle Plain Text)
  1. atrm now `echo hello >> hello2`

so i guess you should use

Shell Scripting Syntax (Toggle Plain Text)
  1. atrm now +3 days `/path/scriptname -foo -bar`

note: the ` prolly isn't nessasery in your case

and if that fails the other way i guess is to do this would be to

Shell Scripting Syntax (Toggle Plain Text)
  1. echo /path/scriptname -foo -bar > /path/execat && at now +3 days -f /path/execat
Reputation Points: 21
Solved Threads: 10
Junior Poster
Paul.Esson is offline Offline
181 posts
since Feb 2005
Oct 28th, 2008
0

Re: bash:redirecting stdin to at command

Hey Guys, I know this is a really old thread but I thought I could clear this up for you quickly.

In bash, STDIN redirection using the < or << operator expects a file on the file system as it's right hand argument. So, when you are running:

at now +3 days << /path/scriptname -foo -bar

you are actually telling bash "Open the file /path/scriptname, and dump it's content to the at command". However, the -foo and -bar are considered additional arguments to at, and are passed as such. I'm sure you were getting an error stating that the time you entered on the command line was garbled, or that at didn't understand your parameters.

To accomplish what you want in older versions of bash, you should be using the pipe operator like so:

command1 | command2

This will take the output of command1 and attach it to the input of command2. SO, if you did:

echo "/path/to/script -foo -bar" | at now + 1 min

at would execute, and prepare to schedule a job for one minute from now. THEN, the echo command would run, dumping the path to your program, a carriage return, and then an end of file to at's prompt. At would accept the command, schedule the job, and return to the command line.

Newer version of bash also support inserting a single string into the input stream of a command using the <<< operator, as such:

at now +1 min <<< "/path/to/script -foo -bar"

Which is closer to the syntax you were trying to use originally. You should be careful not to confuse <, << with <<<.

-Dan
Reputation Points: 10
Solved Threads: 0
Newbie Poster
unacoder is offline Offline
1 posts
since Oct 2008
Nov 6th, 2008
0

Re: bash:redirecting stdin to at command

Hey - alternatively you can do this natively with the at command:

Shell Scripting Syntax (Toggle Plain Text)
  1. at now +3 days <enter>
  2. /path/to/script <enter>
  3. Ctrl-D

The at command actually waits for a Ctrl-D (EOF) for termination. You can feed it an entire command by echoing want you want to run and piping that to the at command - or you can just type - I find it to be easier personally.

Edit:
But note - everything on every line is executed all at once. So for instance, if you want a script to run and then have another script run after, it won't work.

For instance, I was trying to run a dbexport once on an AIX/Informix system - once the dbexport was done, I wanted to tar and then gzip the file. I tried the following:

Shell Scripting Syntax (Toggle Plain Text)
  1. at 0500 Tomorrow
  2. cd /backup/dir
  3. dbexport my_database
  4. cd my_database.exp
  5. tar -cvf ../my_database *
  6. gzip -S .gtz /path/to/storage my_database

Since all the commands dumped at once, the export ran fine, but the rest of the commands failed because none of what it was looking for was in the right place yet.

I ended up just taking the code above and putting into a script and then running that with the at command, which worked fine - but don't expect at input to be run sequentially.
Last edited by omrsafetyo; Nov 6th, 2008 at 6:04 pm.
Reputation Points: 13
Solved Threads: 9
Junior Poster in Training
omrsafetyo is offline Offline
58 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Currency format in Bash Script
Next Thread in Shell Scripting Forum Timeline: Using Shell Script how to send mail automatically





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC