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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
11-30-2016, 07:29 AM
#1
LQ Newbie
Registered: Nov 2016
Posts: 12
Rep:
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:
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 #> < OPTIONS > are 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?
11-30-2016, 07:42 AM
#2
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912
How are you logging in?
What is in the shell script?
11-30-2016, 10:04 AM
#3
LQ Newbie
Registered: Nov 2016
Posts: 12
Original Poster
Rep:
Quote:
Originally Posted by
jpollard
How are you logging in?
What is in the shell script?
I'm logging in via ssh. the shell script is:
11-30-2016, 10:06 AM
#4
Senior Member
Registered: Feb 2003
Distribution: debian
Posts: 4,137
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.
11-30-2016, 11:09 AM
#5
LQ Newbie
Registered: Nov 2016
Posts: 12
Original Poster
Rep:
Quote:
Originally Posted by
Shadow_7
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 . sh : line 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 ( pi ) gid = 1000 ( pi ) groups = 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
11-30-2016, 01:54 PM
#6
Member
Registered: Nov 2012
Posts: 293
Rep:
Quote:
Originally Posted by
markplus
I'm logging in via ssh. the shell script is:
What if your script was
Code:
#!/bin/sh
vncserver :1
11-30-2016, 02:03 PM
#7
Member
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 421
Rep:
Quote:
Originally Posted by
jpollard
How are you logging in?
What is in the shell script?
^ Care to post this?
11-30-2016, 02:05 PM
#8
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
That is answered in posts 3 and 5.
11-30-2016, 02:24 PM
#9
Member
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 421
Rep:
Hmmm... I must be getting old or blind as I don't see any script contents.
11-30-2016, 02:30 PM
#10
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
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 02:35 PM .
11-30-2016, 02:39 PM
#11
LQ Newbie
Registered: Nov 2016
Posts: 12
Original Poster
Rep:
Quote:
Originally Posted by
af7567
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 ^ M : bad interpreter : No such file or directory
But /bin/sh exists.
11-30-2016, 02:46 PM
#12
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
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 02:47 PM .
11-30-2016, 02:48 PM
#13
LQ Newbie
Registered: Nov 2016
Posts: 12
Original Poster
Rep:
Quote:
Originally Posted by
szboardstretcher
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 ] [ option ] script - 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
11-30-2016, 02:49 PM
#14
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
Just the second line then. Leave out the #!/bin/bash -x
Still type it though.
Code:
/usr/bin/vncserver -- ':1' &
11-30-2016, 02:53 PM
#15
Member
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 421
Rep:
Let me grab my magnifying glass.
What's the content of:
and for good measure:
Code:
ls -l /bin/bash /bin/sh
printenv
All times are GMT -5. The time now is 01:21 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News