| | |
bash:redirecting stdin to at command
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2005
Posts: 1
Reputation:
Solved Threads: 0
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.
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.
If i understand what your trying to do try atrm
I just attempted this as a small test
so i guess you should use
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
I just attempted this as a small test
Shell Scripting Syntax (Toggle Plain Text)
atrm now `echo hello >> hello2`
so i guess you should use
Shell Scripting Syntax (Toggle Plain Text)
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)
echo /path/scriptname -foo -bar > /path/execat && at now +3 days -f /path/execat
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Apr 2008
Posts: 58
Reputation:
Solved Threads: 9
Hey - alternatively you can do this natively with the at command:
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:
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.
Shell Scripting Syntax (Toggle Plain Text)
at now +3 days <enter> /path/to/script <enter> 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)
at 0500 Tomorrow cd /backup/dir dbexport my_database cd my_database.exp tar -cvf ../my_database * 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.
![]() |
Similar Threads
- python and bash (Python)
- Capture stdin output from popen2 (Python)
- Searching WinXP using win-bash and Gnu grep (Computer Science)
- Take input from a file and perform a command (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: Currency format in Bash Script
- Next Thread: Using Shell Script how to send mail automatically
| Thread Tools | Search this Thread |





