Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-26-2012
Registered User
 
Join Date: Apr 2012
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Data Works on command line but not in script; vncserver on solaris 10

Hi guys. My first post, so be gentle...
On my Solaris 10 machine vnc server is running. I need a command to extract most recent client session number (screen). So with:
Code:

Code:
bash-3.2# ps -ef | grep vnc | grep Xaut
    root 19805 19797   0 15:41:44 ?           0:01 Xvnc :4 -inetd -once -securitytypes=none -desktop Infinera DNA -auth //.Xauthor
    root 19785 19777   0 15:41:24 ?           0:01 Xvnc :3 -inetd -once -securitytypes=none -desktop Infinera DNA -auth //.Xauthor
    root 19765 19757   0 15:41:00 ?           0:01 Xvnc :2 -inetd -once -securitytypes=none -desktop Infinera DNA -auth //.Xauthor


I can see them all. Then with
Code:

Code:
bash-3.2# ps -ef | grep vnc | grep Xau| sort -k4 | tail -1 | awk '{print $9}' | tr -d ':'
4

I get what I need - just number 4. I've created few Firefox profiles called vnc1, vnc2, vnc3 and vnc4. Now I am trying to use above command to choose the profile name which correlates with session number in firefox command in /.vnc/xstarup:
Code:

Code:
#!/bin/sh

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
twm &
firefox -P vnc$(ps -ef | grep vnc | grep Xau| sort -k4 | tail -1 | awk '{print $9}' | tr -d ':') &

However Firefox is not deriving correct profile name from the command. For this example it should be - firefox -P vnc4
Vnc is showing this error in the log file:
Code:

Code:
  //.vnc/xstartup: syntax error at line 6: `)' unexpected

Could you please let me know what's wrong with firefox command syntax?
Cheers,
cp6uja
Moderator's Comments:
Code tags for code, please.
Sponsored Links
    #2  
Old 04-26-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,139
Thanks: 3
Thanked 954 Times in 933 Posts
Use #!/bin/bash instead of #!/bin/sh .
The Following User Says Thank You to bartus11 For This Useful Post:
cp6uja (04-26-2012)
Sponsored Links
    #3  
Old 04-26-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,371
Thanks: 490
Thanked 2,534 Times in 2,417 Posts
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)



Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
    #4  
Old 04-26-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,371
Thanks: 490
Thanked 2,534 Times in 2,417 Posts
When you type that code into your terminal, you are using bash.

When you run that from a script, you are using /bin/sh, which may be something totally different, something that doesn't understand $( ) syntax, only backticks ` `.
The Following User Says Thank You to Corona688 For This Useful Post:
cp6uja (04-26-2012)
Sponsored Links
    #5  
Old 04-26-2012
Registered User
 
Join Date: Apr 2012
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Many thanks guys. Now it looks so obvious, but I would've never thought of it myself.
Sponsored Links
    #6  
Old 04-26-2012
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
(The other posters have diagnosed this problem correctly).
On Solaris 10 the /bin/sh is the original Bourne Shell which does not recognise many of the Shell extensions which are available in bash and ksh . On other modern unix Operating Systems you can find that /bin/sh is actually the Posix Shell or on many Linux systems it is bash.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
simple php/expect script works from command line but not from web jacksona2 Shell Programming and Scripting 7 06-02-2011 12:50 PM
Works on command line but not in script anthonyjstewart UNIX for Dummies Questions & Answers 4 03-04-2011 09:29 AM
This code works in the command line but not in a shl script rechever Shell Programming and Scripting 1 04-06-2010 09:36 AM
Zgrep works at command line but not in script? Cailet Shell Programming and Scripting 2 05-06-2009 01:07 AM
script works on command line, not in cron job JackTheTripper UNIX for Dummies Questions & Answers 7 06-27-2007 01:51 AM



All times are GMT -4. The time now is 04:56 PM.