Shell script for more than one command
Posted 02 December 2004 - 03:53 PM
Posted 02 December 2004 - 05:29 PM
Here is a snippet from some of my code from home:
ftp -v -i $i <<**
This will execute the rm command right after the ftp command...does this help?
Posted 02 December 2004 - 09:46 PM
What are you trying to acomplish I may already have a script you can hack at. When I get some time I'll post up some of my nautilus scripts I use for various things. Maybe some people can find them helpfull.
Posted 03 December 2004 - 02:11 AM
you can concatenate multiple commands in a script e.g. in this way ...
[sup]#!/bin/sh baseDir="~/script_commands" outFile="$baseDir/testfile_$( date +%Y%m%d-%H%M%S ).txt" alias cmdSeq="mkdir -p $baseDir ; cp /var/log/messages $outFile ; tail -n 5 $outFile" cmdSeq unset cmdSeq echo "all done"[/sup]
The "alias"-thingie here is necessary and it is also often a quite useful method as e.g. a straight invocation of the commands would not work properly ...
[sup]NO-GO-EXAMPLE ... cmdSeq="mkdir -p $baseDir ; cp /var/log/messages $outFile ; tail -n 5 $outFile" $cmdSeq[/sup]
In the above example you'd get error-msgs about invalid commandline options for "mkdir".
A step further: If you want to ensure that the command-sequence only runs through if there are no errors encountered, you should concatenate the commands with ampersands ("&") like this ...
[sup]EXAMPLE: ensure proper exec. of previous cmd ... cmdSeq="mkdir -p $baseDir & cp /var/log/messages $outFile & tail -n 5 $outFile" $cmdSeq[/sup]
But I'm sure you already knew that one from compiling 2.4-kernels (make & make dep & make xyz & make world_go_round ...".
As it goes for a "script corner": I wholehartedly support this idea. And if anyone's interested, I could throw in e.g. an iptables-setup script that utilizes "arrays in bash-scripts" for hosts and services. Neat stuff regarding string handling and "loops" in there
hope that helps
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users