LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   trying to run a script in the background redirect the output to a file (https://www.linuxquestions.org/questions/linux-newbie-8/trying-to-run-a-script-in-the-background-redirect-the-output-to-a-file-788501/)

jdwalk 02-11-2010 12:52 PM

trying to run a script in the background redirect the output to a file
 
I wrote a short script that sleeps for 30 seconds then outputs "Done" to the screen:

sleep 30
echo Done

now I want to re-direct the output to a file, I tried:

./scriptName& > fileName

Didn't work, "Done" still came out to the screen.

repo 02-11-2010 01:05 PM

Try
Code:

sleep 30
echo Done > file


jdwalk 02-11-2010 01:16 PM

tried it but couldn't do any thing else until it finished, I just want it running in the background so I can do other work.

P.S. I am very new to LINUX

David1357 02-11-2010 01:33 PM

Quote:

Originally Posted by jdwalk (Post 3860558)
./scriptName& > fileName

You have the redirection after the request to put the process in the background. Try
Code:

# ./scriptName > fileName 2>&1 &
The "2>&1" will redirect errors as well as normal output.

chrism01 02-11-2010 05:16 PM

Code:

./scriptName > fileName 2>&1 &
need to tell it where to put stdout first then re-direct stderr to stdout

David1357 02-12-2010 07:50 AM

Quote:

Originally Posted by chrism01 (Post 3860801)
need to tell it where to put stdout first then re-direct stderr to stdout

Good catch. I fixed it in my post.

Deepak Poul 10-30-2019 08:34 AM

When i run a python script in the background and redirect the result to a file the output is coming only few minutes
 
The redirection the result of a background python script to the file,the redirection of output is not happening after few lines.
I'm running a python script in linux ubuntu os:
python3 /pathtoscript/script.py > file.txt 2>&1 &

scasey 10-30-2019 10:17 AM

Quote:

Originally Posted by Deepak Poul (Post 6052219)
The redirection the result of a background python script to the file,the redirection of output is not happening after few lines.
I'm running a python script in linux ubuntu os:
python3 /pathtoscript/script.py > file.txt 2>&1 &

This thread is over nine years old -- and your question is not the same issue. You should have opened a new thread with your new and different question. You can use the report button to request the mods to split this off to a new thread.

That said, your redirection looks right. What do you mean by "not happening?"
What happens if you run the script in the foreground with no redirection? Do you get more lines than you do in the file?


All times are GMT -5. The time now is 04:39 PM.