LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-11-2010, 01:52 PM   #1
jdwalk
LQ Newbie
 
Registered: Feb 2010
Posts: 9

Rep: Reputation: 0
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.
 
Old 02-11-2010, 02:05 PM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Try
Code:
sleep 30
echo Done > file
 
Old 02-11-2010, 02:16 PM   #3
jdwalk
LQ Newbie
 
Registered: Feb 2010
Posts: 9

Original Poster
Rep: Reputation: 0
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
 
Old 02-11-2010, 02:33 PM   #4
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by jdwalk View Post
./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.

Last edited by David1357; 02-12-2010 at 08:49 AM. Reason: Fixed redirection error.
 
Old 02-11-2010, 06:16 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Code:
./scriptName > fileName 2>&1 &
need to tell it where to put stdout first then re-direct stderr to stdout
 
Old 02-12-2010, 08:50 AM   #6
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by chrism01 View Post
need to tell it where to put stdout first then re-direct stderr to stdout
Good catch. I fixed it in my post.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Scripting: Redirect output of entire script to file & screen Kristijan Programming 3 10-12-2017 04:17 PM
Unable to redirect script output to a file alien12 Linux - Newbie 4 08-25-2009 04:36 AM
Shell scripting: How to redirect output from within the script itself? Arodef Linux - General 4 05-23-2006 08:30 PM
Redirect script output to log window in wxPython wapcaplet Programming 1 07-04-2004 09:59 PM
Can I redirect script output to a file without ">> $LOGFILE" at the end of each line davee Linux - General 1 12-19-2003 06:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration