









|
[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
[NMLUG] Bash Scripting help
On Wednesday, 30 March 2005 13:48, Tim Emerick wrote:
> I've been working on a bash backup script that runs as a cron job.
> To say it's inelegant is an understatement at best. I could use some
> advice on structure and output.
>
> 1. Rotating backup sets is tedious if I wanted to add or delete the
> number of sets to retain. Is there a way to loop using a variable?
Sure, for instance, use a for loop, like:
#!/bin/sh
for ((i=0; i<10; i++)); do
echo $i
done
> 2. When running as a cron job I get an email after the job has run
> showing output. The commands that were run are preceded with a '+'.
> I would like to selectively replace them with something more
> descriptive using echo.
#!/bin/sh
instead of
#!/bin/sh -x
Then only output (writing to stdout/stderr, e.g. via echo) what you want
to see in the cron report.
> 3. I'm using date to give me a start and stop time but I would also
> like a total time that the script took to run.
e.g.
START_TIME=`date +%s`
# do stuff here
STOP_TIME=`date +%s`
DURATION=$((STOP_TIME-START_TIME))
echo Took $DURATION seconds
Have fun! =)
--
Wesley J. Landaker <wjl@icecavern.net>
OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.b9.com/pipermail/nmlug/attachments/20050330/0f84731f/attachment.pgp
|
|