bash:redirecting stdin to at command

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2005
Posts: 1
Reputation: flying is an unknown quantity at this point 
Solved Threads: 0
flying flying is offline Offline
Newbie Poster

bash:redirecting stdin to at command

 
0
  #1
Feb 3rd, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 181
Reputation: Paul.Esson is an unknown quantity at this point 
Solved Threads: 10
Paul.Esson's Avatar
Paul.Esson Paul.Esson is offline Offline
Junior Poster

Re: bash:redirecting stdin to at command

 
0
  #2
Feb 11th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1
Reputation: unacoder is an unknown quantity at this point 
Solved Threads: 0
unacoder unacoder is offline Offline
Newbie Poster

Re: bash:redirecting stdin to at command

 
0
  #3
Oct 28th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 58
Reputation: omrsafetyo is an unknown quantity at this point 
Solved Threads: 9
omrsafetyo omrsafetyo is offline Offline
Junior Poster in Training

Re: bash:redirecting stdin to at command

 
0
  #4
Nov 6th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC