LinuxQuestions.org
Visit Jeremy's Blog.
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 03-28-2009, 10:50 AM   #1
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Rep: Reputation: 16
Question $! Doesn't Work In Client


Hi All!

I have a script like the following:

ssh -f xyz@abc.def.edu "cd /home/xyz/ ; nohup java -Xmx1024m abc <ParamFile> & ; JAVAParent=$!; echo $JAVAParent >> parentPID.txt"

The script essentially runs a java program in the client machine abc.def.edu and outputs the PID of this process to a file. [We know $! holds the PID of the last spawned process. ]

However while running this script, I find that JAVAParent isn't holding any value. In fact while I debug this script using bash -x script.sh, I find that the line corresponding to JAVAParent=$! is shown as JAVAParent= ; (there is no $! here!).

I would be more than pleased if you could help!

Thanks in advance!
 
Old 03-28-2009, 01:00 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Hi.

The $! is being evaluated before being sent as part of the command line. Use hard (single) quotes around the command line to stop this. i.e.
ssh -f xyz@abc.def.edu 'cd /home/xyz/; nohup java -Xmx1024m abc <ParamFile> & JAVAParent=$!; echo $JAVAParent >> parentPID.txt'

Dave
 
Old 03-30-2009, 10:25 AM   #3
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Original Poster
Rep: Reputation: 16
Unhappy

Hi ilikejam!

Thanks for the reply. It is working now. But it seems the process is actually not running. That is,

ssh -f xyz@abc.def.edu 'cd /home/xyz/; nohup java -Xmx1024m abc <ParamFile> & JAVAParent=$!; echo $JAVAParent >> parentPID.txt'

I don't find the abc file running. Though the parentPID.txt has a Process id now, I don't find the process corresponding to it in top.

Why is that?

Looking forward to your help!
 
Old 03-30-2009, 10:35 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,988
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Wouldn't that depend on what it's meant to do, and how
long it ran for (is meant to run for)?
 
Old 03-30-2009, 11:27 AM   #5
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Original Poster
Rep: Reputation: 16
Hi Tinkster!

That program actually runs for hours! However I would like to have some other process run parallely in another client using the process id of this parent process. That is why, I made it nohup and ended it with &.

I would greatly appreciate any help as I have been stuck with this for two days now!
 
Old 03-30-2009, 01:05 PM   #6
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
See if there's any clues in /home/xyz/nohup.out - the stdout and stderr from the java process should be in there.

Dave
 
Old 03-30-2009, 02:07 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,988
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Quote:
Originally Posted by senthilmuthiah View Post
Hi Tinkster!

That program actually runs for hours! However I would like to have some other process run parallely in another client using the process id of this parent process. That is why, I made it nohup and ended it with &.

I would greatly appreciate any help as I have been stuck with this for two days now!
Does the code actually work if you run it interactively?


Cheers,
Tink
 
Old 03-31-2009, 06:06 PM   #8
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Original Poster
Rep: Reputation: 16
Unhappy

Quote:
Originally Posted by ilikejam View Post
See if there's any clues in /home/xyz/nohup.out - the stdout and stderr from the java process should be in there.

Dave
Hey Dave!

The nohup.out file itself isn't created! What on earth is happening?!
 
Old 03-31-2009, 06:07 PM   #9
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by Tinkster View Post
Does the code actually work if you run it interactively?


Cheers,
Tink
Hey Tink!

Yes, the code doesn't work if I run interactively! I guess, the problem is actually with the use of $! . I am not sure... Please help!
 
Old 03-31-2009, 06:08 PM   #10
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by Tinkster View Post
Does the code actually work if you run it interactively?


Cheers,
Tink
But if I run the commands separately one by one, they do work!
 
Old 04-01-2009, 09:36 AM   #11
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Original Poster
Rep: Reputation: 16
Unhappy

Some one please help!
 
Old 04-01-2009, 09:55 AM   #12
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
I noticed a ';' after the '&' in your first post - it shouldn't be there.

Dave
 
Old 04-01-2009, 01:28 PM   #13
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Original Poster
Rep: Reputation: 16
All!

I was able to find where the problem was. Note that the $<variableName> whenever is inside " ", should have a '' surrounding it!

This was the problem I had. I can't believe how crazy these mistakes can drive us!

Thanks for all your help!
 
  


Reply

Tags
client, last, pid, process, quotes, ssh


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
Cisco VPN Client? How to get it to work. Jesgrew Suse/Novell 1 11-26-2007 01:51 AM
Citrix client installed, but does not work xri Linux - Networking 2 01-07-2007 08:25 PM
Gnome-terminal does not work well as a BBS client ljx980645 Linux - Software 1 02-20-2006 10:52 AM
I cant get an MSN9 client to work on Debian Woody. HELP! flagrant Linux - Software 2 11-05-2003 04:08 AM
Cisco VPN Client 4.01 does not work in RH 9 xmongra Linux - Software 10 08-05-2003 07:56 PM


All times are GMT -5. The time now is 06:59 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration