Bash Sheet
13 Aug 2013, Posted by All Posts, Computer Talk inHere is an example of a loop that will compress and send how ever many files are found to another server.
!/bin/bash
first_list=’/ [path] / [to] / [files] / *.*’
for raw in $first_list
do
gzip -9 $raw
done
second_list=’/ [path] / [to] / [files] / *.gz’
for gz in $second_list
do
scp $gz [user] @ [destination hostname/ip]:/ [path] / [to] / [destination] / [directory]
if [ $? != 0 ]; then
{
echo `eval date +%x` `eval date +%X` ” – transfer failed: “$gz >> / [path] / [to] / [files] / results / fail.txt
exit 1
}
fi
echo “transfer complete: “$gz >> / [path] / [to] / [files] / results / success.txt
# uncomment below to remove file once sent
# rm -f $gz
done
This is a great site to use (in addition to this one) for some more bash scripting help.
TAGS > automatic, bash, bashorun, bashorun.com, execute, linux, scripts, unix
NO COMMENT