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

Mark Haney mark.haney at gmail.com
Wed Aug 21 14:19:45 UTC 2013


Okay, I wasn't sure if that would work or not since I was running the
internal script as a different user.  Thanks.



On Wed, Aug 21, 2013 at 10:11 AM, Reindl Harald <h.reindl at thelounge.net>wrote:

>
>
> 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
>
>


-- 
Caesar si viveret, ad remum dareris.

Mark Haney
Software Developer/Consultant
mark.haney at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.fedoraproject.org/pipermail/users/attachments/20130821/763156c3/attachment.html>


More information about the users mailing list