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 04-13-2005, 03:54 PM   #1
rjkfsm
Member
 
Registered: Apr 2004
Location: Charleston, SC
Distribution: Debian, Gentoo, Knoppix & DSL
Posts: 122

Rep: Reputation: 15
Quik SSH question


If I start an executable script from an SSH session, and redirect the output to a null device, am I not supposed to get a prompt back?

RK
 
Old 04-13-2005, 04:06 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Not if the script is still running.

You can background it with:
/path/to/script > /dev/null &

Or press Ctrl+z when it is running.
 
Old 04-13-2005, 05:23 PM   #3
MA_D
Member
 
Registered: Apr 2005
Location: Iowa
Distribution: Archlinux/RHEL/FreeBSD
Posts: 41

Rep: Reputation: 15
Unless it prints to stderr. There is stdout and stderr. If you wanna make absolutely sure your redirect gets all console text you must do this:

script.sh 2>&1 >> /dev/null

2>&1 can also be stderr>stdin I think.
 
Old 04-13-2005, 07:48 PM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
to MA_D: I'm sorry, but you're slightly wrong;
$ foo.sh 2>&1 >> /dev/null #*does* work, but it's a bit clumsy
$ foo.sh &> /dev/null #also works; &> means `redirect stderr and stdout to'
$ foo.sh 2>&1 # redirects stderr to stdout (or, transitively, to where stdout goes).
You can't redirect from a program's stdout/stderr to its stdin; I've tried some hackery with pipe files, and although they are very neat, they don't redirect to stdin;

however, I have found
$ mknod pipe p
$ cat < pipe > pipe
a useful tool. It enables you to write to a pipe without having to wait for the data to be consumed.

also, whether or not a process produces output (to either &1 or &2) shouldn't affect how it goes into the background.

for more, read `advanced bash scripting guide' (or your preferred tutorial).

hth --Jonas
 
Old 04-13-2005, 08:09 PM   #5
rjkfsm
Member
 
Registered: Apr 2004
Location: Charleston, SC
Distribution: Debian, Gentoo, Knoppix & DSL
Posts: 122

Original Poster
Rep: Reputation: 15
Grrrrrrrrrrrrrrrreat

Well, none of these solved the problem because when I close the SSH session, the script gets killed. Bash ends up being a child process of SSHD and the script is a child process of bash. Close out the session and SSHD kills it's bash process which kills the script.

I found a script that I could modify and can be put in the init.d folder and when run from boot up, it works........ So, I am happy.

Thank you to you all for your time. I learned a lot.

RK
 
Old 04-13-2005, 08:21 PM   #6
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
np. Also, to google for: zombified process. iirc, this happens when a process loses its parent; it might contain info relevant to your situation.
 
Old 04-14-2005, 12:23 PM   #7
MA_D
Member
 
Registered: Apr 2005
Location: Iowa
Distribution: Archlinux/RHEL/FreeBSD
Posts: 41

Rep: Reputation: 15
Quote:
Originally posted by jonaskoelker
to MA_D: I'm sorry, but you're slightly wrong;
$ foo.sh 2>&1 >> /dev/null #*does* work, but it's a bit clumsy
$ foo.sh &> /dev/null #also works; &> means `redirect stderr and stdout to'
$ foo.sh 2>&1 # redirects stderr to stdout (or, transitively, to where stdout goes).
You can't redirect from a program's stdout/stderr to its stdin; I've tried some hackery with pipe files, and although they are very neat, they don't redirect to stdin;

however, I have found
$ mknod pipe p
$ cat < pipe > pipe
a useful tool. It enables you to write to a pipe without having to wait for the data to be consumed.

also, whether or not a process produces output (to either &1 or &2) shouldn't affect how it goes into the background.

for more, read `advanced bash scripting guide' (or your preferred tutorial).

hth --Jonas
Ok, change every occurance of stdin in my post to stdout and I'm right :-p. Anyway, 2>&1 does the job, I use it almost daily.
 
Old 04-14-2005, 12:40 PM   #8
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
s/stdin/stdout/g: accepted. I'm sure 2>&1 > /foo/bar does the job, I'm just trying to show how &> can save you a lot of typing -- this is what I like to call `constructive laziness', a virtue in the field of computer science
 
  


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
ssh question??? yenonn Linux - Security 5 02-25-2005 03:49 PM
ssh-agent/ssh-add question mega Slackware 2 01-26-2005 04:09 AM
Quik Question? Darkness-Inc Linux - Newbie 2 04-21-2004 11:49 AM
ssh question emetib Linux - Software 2 07-13-2003 01:27 PM
MandrakePPC linux + quik + initrd Jon- Linux - Software 0 10-25-2002 11:33 AM


All times are GMT -5. The time now is 06:47 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