Trouble calling 'startx' in Start-Up Script

Hello everyone! This is my first post!

I'm trying to set-up a Thin Client that when booted will automatically log into a server for vnc.
Right now, I have a bash shell script at /etc/rc.d/thinclient
Code:
#!/bin/sh

echo "thinclient script starting..."

SERVER_IP="192.168.1.124"
STARTX_PATH="/usr/local/bin/startx"
VNCVIEWER_PATH="/usr/local/bin/vncviewer"
VNCVIEWER_ARGUMENTS="localhost:1 -geometry 1280x1024 -passwd /etc/thinclient/vncpasswd"

echo "Step 1: Attempting ssh connection as 'ThinAccount' to server at $SERVER_IP"
/usr/bin/ssh -f -i /etc/thinclient/id_rsa -L 5901:localhost:5900 -N ThinAccount@$SERVER_IP

echo "Step 2: *Unimplemented* Server will attempt connection to ThinClient"

echo "Step 3: Calling 'startx' with 'vncviewer'"
$STARTX_PATH $VNCVIEWER_PATH $VNCVIEWER_ARGUMENTS

I know that all my lines of code work, because the script runs as expected if executed after having logged in.
Code:
login: root
password:
FreeBSD-ThinClient# cd /etc/rc.d
FreeBSD-ThinClient# ./thinclient
Typing all that produces the expected result, filling the screen with wonderful, fullscreen VNC goodness.
However, I want the result without the typing, at startup.

The only clue I have is the output at startup.
Check it out!
Code:
/etc/rc: WARNING: Ignoring scratch file /etc/rc.d/thinclient~
thinclient script starting...
Step 1: Attempting ssh connection as 'ThinAccount' to server at 192.168.1.124
Step 2: *Unimplemented* Server will attempt connection to ThinClient
Step 3: Calling 'startx' with 'vncviewer'
xauth: not found
xauth: not found
xauth: not found
xauth: not found
xauth: not found
xinit: not found
xauth: not found
...
login:

Seemingly, the problem is that xorg cannot properly start. But why?

Any help from the friendly FreeBSD community would be much appreciated! Could the problem be not having a $PATH variable?

-Peter
 
Dang, yo!

I feel like a fool! But at the same time I feel good, because my script is working.
It was just the missing $PATH variable. Oh well.

Is there a more elegant solution than just adding:
Code:
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
?

Now I have a new problem, that being that my script doesn't finish, so sshd, for example, doesn't get started.
Is there a better place to put this script?

Thanks again,
-Peter
 
TMTOWTDI. You could run it from /etc/rc.local. /etc/ttys is another way, and that leaves the rest of the system fairly normal. Set up an auto-login entry in /etc/gettytab and use that with the ttys entry.

Also: sh != bash, and using either for root's shell can make for some interesting times later.
 
You could perhaps add '&' to the end of the startx command to move it to background, so the script finishes.

Or you could create another script called 'start_thinclient' which simply runs your thinclient script with an '&' on the end to move the whole script into the background.
 
Thank you to both of you!

I learned a lot trying wblock's suggestions, but I eventually decided that, for security reasons, I actually don't want any users logged in.

Strangely enough, adding '&' to the end of the startx command didn't work. If I remember correctly, it managed to black out the screen. However, creating a 'start_thinclient' script in /etc/rc.d/ and in that running my main script in the background worked great!

Excellent!
-Peter
 
Not sure exactly what you mean, but avoiding the autologin means you'll be running as root. An autologin entry doesn't show a login, it just logs in automatically. In this case, as a non-root user to run X. Because I've done this several times but forget how each time, I'm going to show it here:

/etc/gettytab
Code:
# WB: autologin console as user "user"
A|Al|Autologin console:\
        :ht:np:sp#115200:al=user

Then use that entry in ttys so user will automatically log in when the system starts that ttyv (at startup):
/etc/ttys
Code:
ttyv1   "/usr/libexec/getty Al"       xterm  on  secure

user's shell is set to /bin/csh in /etc/passwd.

Finally, add code to start X in "user"'s shell startup. For csh(1), it goes at the end of .cshrc.
/home/usr/.cshrc
Code:
# WB: startx if it isn't already running
set XPID = `/usr/bin/pgrep xinit`
if ( { [ -n "$XPID" ] } ) then
  #echo "X is already running"
else
  startx
  logout
endif

X will use the .xinitrc in user's home directory.
 
As I have updated our lab to 12.2-RELEASE, I switched back to xstart for headless clients.
This thread was the perfect solution.
Thank you wblock@ I have updated your script for us bash shell users:

for .bashrc

Code:
#  startx if it isn't already running
XPID=`/usr/bin/pgrep Xorg`
if  [[ -z $XPID ]]
then
  /usr/local/bin/startx
  logout
fi
 
Back
Top