• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Shell script and a log file

The Keeper

Senior member
I have this shell script scheduled to run periodically doing some maintenance duties. Now, lots of commands have accumulated into this one shell script, including but not limited to database exports, checks, file backups (tar & gzip combination), etc, etc.

Now I really would like to have the shell script to write a log file of everything it does. How should I go around to implement it? All I need is that it writes the output I would see when running it manually in a shell to a log file, no need for fancy time stamping or anything.

Thanks a bunch. 🙂
 
Perhaps the script command would work for this, but I'm not sure since there is no real terminal output.

Joe
 
Couple ways. Look at the first line in the script to see what shell it's going to run it in, i.e: #!/bin/ksh would be an example.

At a prompt, run ksh -x /path/of/script > /tmp/script.out 2>&1 &
or bash -x or sh -x, etc...

If it's a cron, add the same before the call of the command.

You can stick in a set -x after the shell declaration within the script, but I am not sure if you want to edit the script if it's under someone else's version-ing control.
 
crontab, I'm sorry but what you said went over the top of my head. 🙂
Crusty, it is normally ran by cron. Though some times manually too.
 
head/more/cat/view the script to see see what shell the script is running in. Just look at the very first line. Assume it says #!/bin/bash

i assume you cron job looks something like this:

0 0 * * * source .an_env; /path/to/the/script

Change it to:

0 0 * * * source .an_env; bash -x /path/to/the/script > /tmp/script_output.txt 2>&1
 
Back
Top