LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 11-30-2016, 08:29 AM   #1
markplus
LQ Newbie
 
Registered: Nov 2016
Posts: 12

Rep: Reputation: Disabled
Command working on command line but not in shell script


Hello,

on my Raspberry Pi I've installed tightvnc server. in order to start the server, I've gotta write on the command line:
Quote:
vncserver :1
When using the command line ("vncserver :1"), it works flawlessly and results on following response:
PHP Code:
pi@raspberrypi:/var/www/shellscr vncserver :1

New 'X' desktop is raspberrypi:1

Starting applications specified in 
/home/pi/.vnc/xstartup
Log file is 
/home/pi/.vnc/raspberrypi:1.log 
When executing from within a shell script ("./script.sh"), the server won't start and the response is:
PHP Code:
pi@raspberrypi:/var/www/shellscr $ ./vnc.sh
TightVNC Server version 1.3.9

Usage
vncserver [<OPTIONS>] [:<DISPLAY#>]
       
vncserver -kill :<DISPLAY#>

<OPTIONSare Xtightvnc options, or:

        -
name <DESKTOP-NAME>
        -
depth <DEPTH>
        -
geometry <WIDTH>x<HEIGHT>
        -
httpport number
        
-basehttpport number
        
-alwaysshared
        
-nevershared
        
-pixelformat rgb<NNN>
        -
pixelformat bgr<NNN>

See vncserver and Xtightvnc manual pages for more information
It's apparently not a rights issue as it is executed by the same user and other shell scripts with the same structure work flawlessly.

Can anyone help?
 
Old 11-30-2016, 08:42 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
How are you logging in?
What is in the shell script?
 
Old 11-30-2016, 11:04 AM   #3
markplus
LQ Newbie
 
Registered: Nov 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
How are you logging in?
What is in the shell script?
I'm logging in via ssh. the shell script is:
PHP Code:
vncserver :
 
Old 11-30-2016, 11:06 AM   #4
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
Perhaps:

Code:
/usr/bin/vncserver -- ':1' &
in the script. The $PATH, id, or group might differ in script than on the cli. Some stuff you could add to help debug things.

Code:
echo "PATH:"
echo $PATH
echo "SHELL:"
echo $0
echo "ID:"
id
echo "which vncserver"
which vncserver
To debug differences between your shell execution and your CLI.
 
1 members found this post helpful.
Old 11-30-2016, 12:09 PM   #5
markplus
LQ Newbie
 
Registered: Nov 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Shadow_7 View Post
Perhaps:

Code:
/usr/bin/vncserver -- ':1' &
in the script. The $PATH, id, or group might differ in script than on the cli. Some stuff you could add to help debug things.

Code:
echo "PATH:"
echo $PATH
echo "SHELL:"
echo $0
echo "ID:"
id
echo "which vncserver"
which vncserver
To debug differences between your shell execution and your CLI.

Unfortunately the suggested command results in:
PHP Code:
pi@raspberrypi:/var/www/shellscr $ ./vnc.sh
./vnc.shline 1: $'\r'command not found 
The debugging script returns:
PHP Code:
pi@raspberrypi:/var/www/shellscr $ ./test.sh
PATH
:
/
usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
SHELL
:
./
test.sh
ID
:
uid=1000(pigid=1000(pigroups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),33(www-data),44(video),46(plugdev),60(games),100(users),101(input),108(netdev),997(gpio),998(i2c),999(spi)
which vncserver
/usr/bin/vncserver 
 
Old 11-30-2016, 02:54 PM   #6
af7567
Member
 
Registered: Nov 2012
Posts: 218

Rep: Reputation: 81
Quote:
Originally Posted by markplus View Post
I'm logging in via ssh. the shell script is:
PHP Code:
vncserver :
What if your script was
Code:
#!/bin/sh

vncserver :1
 
Old 11-30-2016, 03:03 PM   #7
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 417

Rep: Reputation: 74
Quote:
Originally Posted by jpollard View Post
How are you logging in?
What is in the shell script?
^ Care to post this?
 
Old 11-30-2016, 03:05 PM   #8
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657
That is answered in posts 3 and 5.
 
Old 11-30-2016, 03:24 PM   #9
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 417

Rep: Reputation: 74
Hmmm... I must be getting old or blind as I don't see any script contents.
 
Old 11-30-2016, 03:30 PM   #10
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657
A picture of his script then?

http://imgur.com/a/drNRw

Keeping in mind that shell scripts can be just lists of commands. Currently, his is a shell script with one line and one command.

Also, he is logging in with SSH as this user, as mentioned:

Quote:
uid=1000(pi) gid=1000(pi) groups=1000(pi)
Also - OP - please use this as the script - but TYPE IT IN and do NOT copy and paste it.

Code:
#!/bin/bash -x
/usr/bin/vncserver -- ':1' &

Last edited by szboardstretcher; 11-30-2016 at 03:35 PM.
 
Old 11-30-2016, 03:39 PM   #11
markplus
LQ Newbie
 
Registered: Nov 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by af7567 View Post
What if your script was
Code:
#!/bin/sh

vncserver :1
This results in:
PHP Code:
pi@raspberrypi:/var/www/shellscr $ ./vnc.sh
-bash: ./vnc.sh: /bin/sh^Mbad interpreterNo such file or directory 
But /bin/sh exists.
 
Old 11-30-2016, 03:46 PM   #12
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657
As i said:

Please use this as the script - but TYPE IT IN and do NOT copy and paste it.

Code:
#!/bin/bash -x
/usr/bin/vncserver -- ':1' &
Every error you have pasted so far is due to copying and pasting. ^M and \r are both control characters incorrectly pasted from windows to nix.

Last edited by szboardstretcher; 11-30-2016 at 03:47 PM.
 
Old 11-30-2016, 03:48 PM   #13
markplus
LQ Newbie
 
Registered: Nov 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by szboardstretcher View Post
A picture of his script then?

http://imgur.com/a/drNRw

Keeping in mind that shell scripts can be just lists of commands. Currently, his is a shell script with one line and one command.

Also, he is logging in with SSH as this user, as mentioned:



Also - OP - please use this as the script - but TYPE IT IN and do NOT copy and paste it.

Code:
#!/bin/bash -x
/usr/bin/vncserver -- ':1' &
Thank you also for explaining to c0wb0y!

The result of the manually typed code in the shell script, that you suggested unfortunately is:
PHP Code:
pi@raspberrypi:/var/www/shellscr $ ./vnc.sh
invalid option
Usage
:  /bin/bash [GNU long option] [option] ...
        /
bin/bash [GNU long option] [optionscript-file ...
GNU long options:
        --
debug
        
--debugger
        
--dump-po-strings
        
--dump-strings
        
--help
        
--init-file
        
--login
        
--noediting
        
--noprofile
        
--norc
        
--posix
        
--rcfile
        
--restricted
        
--verbose
        
--version
Shell options
:
        -
ilrsD or -c command or -O shopt_option         (invocation only)
        -
abefhkmnptuvxBCHP or -o option 
 
Old 11-30-2016, 03:49 PM   #14
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657Reputation: 1657
Just the second line then. Leave out the #!/bin/bash -x

Still type it though.

Code:
/usr/bin/vncserver -- ':1' &
 
Old 11-30-2016, 03:53 PM   #15
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 417

Rep: Reputation: 74
Let me grab my magnifying glass.

What's the content of:

Code:
$DISPLAY
$SHELL
and for good measure:
Code:
ls -l /bin/bash /bin/sh
printenv
 
  


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
Mail runs from command line, not from shell script jackelliott Linux - General 10 03-19-2015 09:18 AM
[SOLVED] there is one name 4 for command-line-parameters in shell script miillerje Linux - Newbie 3 10-21-2012 08:25 AM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 10:12 PM
How to execute a command line in a shell script orgazmo Programming 5 05-09-2005 10:16 AM
Shell Script to read 500files from the command line saravanan1979 Programming 1 09-22-2004 10:44 AM

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

All times are GMT -5. The time now is 10:33 AM.

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
Open Source Consulting | Domain Registration