Log output of bash script when part is run as different user

Reindl Harald h.reindl at thelounge.net
Wed Aug 21 14:11:47 UTC 2013



Am 21.08.2013 16:04, schrieb Mark Haney:
> I've got a bash script that has two parts. 
> 
> 1. runs a script as a different user (using su <username> -c <script>)
> 2. when that part finishes, the script does a copy of the files created to another directory
> 
> I want to log the output of the entire script into one file.  I.e.:
> 
> internal script>external script> logfile 
> 
> What's the best way to do this?  I can clarify, I hope, I've edited this a dozen times to get what I want in as
> clear a message as possible

why do you think you need to care about the internal called one?
you call wathever and say "redirect my output", that belongs to
*anything* called by this script with the only eception of stderr

command 2>> logfile.txt >> logfile.txt

>> is "do not make the file empty, add your output at the end"
> would empty any existing file before
___________________________________________

[harry at rh:~/Desktop/test]$ cat script1.sh
#!/usr/bin/bash
echo "OUTPUT SCRIPT 1"
bash ./script2.sh

[harry at rh:~/Desktop/test]$ cat script2.sh
#!/usr/bin/bash
echo "OUTPUT SCRIPT 2"

[harry at rh:~/Desktop/test]$ ./script1.sh
OUTPUT SCRIPT 1
OUTPUT SCRIPT 2

[harry at rh:~/Desktop/test]$ ./script1.sh > output.txt

[harry at rh:~/Desktop/test]$ cat output.txt
OUTPUT SCRIPT 1
OUTPUT SCRIPT 2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 263 bytes
Desc: OpenPGP digital signature
URL: <http://lists.fedoraproject.org/pipermail/users/attachments/20130821/83b576ab/attachment.sig>


More information about the users mailing list