Re: Logging of commands in a bash script to a file
On 23/04/14 08:06, Daniel Bareiro wrote:
>
> Hi all!
>
> I'm writing a bash script that runs several routing commands. I would
> like these commands, on a part of the script, plus run, are saved to a
> log file.
>
> I guess maybe it could be done by putting the commands in a variable and
> then do:
>
> $CMD
> echo $CMD
>
>
> But perhaps there is a more elegant way to do this in a single line.
For a complete record use 'script'.
$ script ~/log.script -c pathTo/myRoutingScript.sh
At the end of your script I might log the output of 'ip a' and (as
root), 'route' and 'arp'. I'd also likely use the '-v' (verbose) switch
for any route commands in your routing script.
...and I'd make the first line of myRoutingScript.sh:-
#!/bin/bash -x
Alternatively you can just (effectively) combine stderr and stdout and
pipe them to a log file. e.g.:-
2>&1 >> ~/log #after commands in your routing script
>
>
> Thanks in advance.
>
>
> Best regards,
> Daniel
>
Kind regards
Reply to: