Works on command line but not in script; vncserver on solaris 10


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Works on command line but not in script; vncserver on solaris 10
# 1  
Old 04-26-2012
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:
Mod Comment Code tags for code, please.
# 2  
Old 04-26-2012
Use #!/bin/bash instead of #!/bin/sh.
This User Gave Thanks to bartus11 For This Post:
# 3  
Old 04-26-2012
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
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 ` `.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 04-26-2012
Many thanks guys. Now it looks so obvious, but I would've never thought of it myself.
# 6  
Old 04-26-2012
(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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. Shell Programming and Scripting

Works on command line but not in script

OSX 10.9 I am building a script that evaluates the difference between 2 files. Here is a command that does not work transparently. Running this command in Terminal yields great results; however when I put that line in a .sh script, I get the errors shown below. Am I doing something silly? ... (1 Reply)
Discussion started by: sudo
1 Replies

3. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

4. Shell Programming and Scripting

simple php/expect script works from command line but not from web

I have a really basic expect script which I call from php. I works fine when I run the php from the shell, but from the web it appears as if the output buffer gets chopped and never gets all of the contents. php script: (runexpect.php) <?php... (7 Replies)
Discussion started by: jacksona2
7 Replies

5. UNIX for Dummies Questions & Answers

Works on command line but not in script

Hey guys. Hopefully this is an easy one but having reference similar problems on the web I still can't fix it. I am doing a recursive find and replace from a script. Of course I could just run the damn thing from the command line but it's bugging me now and want to get it working. grep -rl... (4 Replies)
Discussion started by: anthonyjstewart
4 Replies

6. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

7. Shell Programming and Scripting

This code works in the command line but not in a shl script

When I run this code from the command line works spinel.middlebury.edu:/u02/sct/banner/bandev2/middlebury/shl:DEV2$ ls ef* eftseq.dat spinel.middlebury.edu:/u02/sct/banner/bandev2/middlebury/shl:DEV2$ file_seq=$( < eftseq.dat) ... (1 Reply)
Discussion started by: rechever
1 Replies

8. Shell Programming and Scripting

Zgrep works at command line but not in script?

Hi all- I'm trying to search through some .gz log files to verify certain feeds have passed through our app. I have a small script that I wrote in hopes that I could automate the checking but haven't been able to get the zgrep to work. When I copy it to the command line directly it works... (2 Replies)
Discussion started by: Cailet
2 Replies

9. Shell Programming and Scripting

works step by step on command line but not in script

Hi all, The following script is fine when I work via command line m=1 c=0 while do echo $m gnokii --getsms IN $m > out.txt; m=`expr $m + 1`; cat out.txt >> message_log; ############ read first crap< <(sed -n '/Text:/{n;p;}' out.txt); read message< <(sed -n '/Text:/{n;p;}'... (2 Replies)
Discussion started by: whamchaxed
2 Replies

10. UNIX for Dummies Questions & Answers

script works on command line, not in cron job

Hey there, I'm a total newbie unix guy here and just picking this stuff up. Have a very small script I put together that works fine from the command line but not once I put it in a cron job. Searched and found this thread and am wondering it it has something to do with setting variables, though the... (7 Replies)
Discussion started by: JackTheTripper
7 Replies
Login or Register to Ask a Question