Can I send output from nohup to multiple files? - nohup

I would like to be able to send the output from nohup to more than one file. Does anybody have any thoughts on this? I cannot find anything about this anywhere

Related

Running shell script with more information

My script get stuck in some point and it doesn't show any error. I would like to know why and where it gets stuck. Is there a possibility to run a script and show me more information what is it running?
I have found -x command to run it in debug mode but I have a lot of scripts which are connected and it doesn't work for me.
With -vvv I have also tried, but somehow it doesn't show more than without it.
Does anyone know another command for that?
Read:
https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html
... and this:
https://unix.stackexchange.com/questions/155551/how-to-debug-a-bash-script
... and if that's not enough, look at the gdb-like bash debugger:
http://bashdb.sourceforge.net/
and many moore...

When should I use file descriptors in bash scripting?

i know what they are, but i dunno when i should use them. Are they useful? I think yes, but I want you to tell me in which situations a file descriptor could be useful. Thanks :D
The most obvious case which springs to mind is:
myProgram >myProgram.output_and_error 2>&1
which sends both standard output and error to the same file.
I've also used:
myProgram 2>&1 | less
which will allow me to page through the output and error in sequence (rather than having error got to the terminal in "arbitrary" places in the output).
Basically, any time when you need to get at an already existing file descriptor, you'll find yourself using this.

How to change current work directory using expect script?

I want to write an expect script which can do some task and in the end change the directory and give control to the user. I tried using
spawn cd path\to\dir
interact
but i am still in the same directory.
Any leads on how to accomplish this using expect ?
To change the directory in an expect script, you don't need to use the keyword "spawn" it works without it.
You may be a little confused, because in the terminal, in which you are executing the script, you will stay in the same directory, but the script changed the directory in which it is doing things.
I suppose you have spawned some command (like ssh, bash) and the spawned command is still running. Then at the end you can do like this:
send "cd /some/dir\r"
interact

How to open a command-line application with a command without closing it?

I am trying to write a script that opens a command-line application (sagemath in this case) which on start up will send a certain command down the pipe (attach a script) without closing the application at the end.
I tried something like:
#!/bin/bash
echo "load(\"script.sage\")" | sage
This, of course, opens sage load the script print the output of the script and closes sage. Adding & at the end of the last line didn't work.
I know that technically I can add this script to the list of scripts which are loaded on startup always but this is not what I want. I thought that it might be done be making a dynamic link at some directory to my script, but not sure if there is such a directory and where it is.
Any suggestions?
Edit:
I didn't know about Expect (I'm a youngster in linux). Reading about, following Mark's suggestion, it a bit I managed to solve this. If this is of any interest to anyone in the future then this does the trick:
#!/usr/bin/expect
set timeout 20
spawn sage
expect "sage:"
send "load(\"script.sage\")\n"
interact
#!/usr/bin/expect
set timeout 20
spawn sage
expect "sage:"
send "load(\"script.sage\")\n"
interact
You could use 'screen' depending on how dynamically you need this script to run. See http://linux.die.net/man/1/screen for info on how to use screen.
You can either:
Use nohup to start the program E.g., nohup "load(\"script.sage\")" | sage.
Or, you can use the disown command.

direct stdout to cache

Does anyone happen to know how to direct STDOUT in Terminal to Cache? Sometimes I would like to copy text from STDOUT somewhere else, e.g. my mail program, and it seems always a bit inconvenient to me to either copy the output manually or create a new temporary file.
Is there an easy way to do this?
Thanks a lot!
Alex
It's not clear exactly what you're asking. But if you're talking about capturing stdout to file whilst still being able to see it on the console, then you can use tee (assuming you're using *nix):
./myApp | tee stdout.txt

Resources