anyone interested in writing a bash script to run vnc on startup?

16k_zx81

Well-Known Member
Reaction score
54
Location
South Australia
I need a script to run VNC on Parted Magic at boot, so the machine can be run remotely when powered on.

Spoke with Patrick, the developer who advised to do it this way:

If you know how to write a bash script you can put one in /pmagic/pmodules/scripts and it will be ran every boot. You could even start a vnc program by adding it to /root/.config/openbox/autostart.sh and then do a save session. The /pmagic/pmodules/scripts method gives you the power do to whatever you need to do.

Unfortunately, I lack the required skills. I cant script.

Just wanted to put this out there in case anyone is interested in a project?

Contra deal, maybe?
 
Last edited:
Easy enough. I'll do it for you.
But I don't have Parted Magic right now to verify stuff.

Gimme a minute or two...
 
Stop the press!!
I gotta pay for this?


Is this what you have? Or am I missing a different version?
https://partedmagic.com/

[EDIT] Ahhh, I see it on Major Geeks.
Downloading....
(Yes, I have a few minutes on my hand)
 
Stop the press!!
I gotta pay for this?


Is this what you have? Or am I missing a different version?
https://partedmagic.com/

[EDIT] Ahhh, I see it on Major Geeks.
Downloading....
(Yes, I have a few minutes on my hand)

Which hand? Left or right? (could not resist)

At any rate there is another thread on here talking about how he started charging. Personally I don't have a problem so I chipped in just to get the latest version.
 
I've never used it... well, I've used parted and the like, just not this distro.
Looks simple enough to do whatever it is the OP wants
 
I'm not seeing the directorie(s) you were referred to on the system I brought up, however here's a VERY basic and simple init script that should start and stop the VNC server daemon and have it listening on DISPLAY:5

Code:
#!/bin/sh

case "$1" in
start)
	/usr/local/bin/vncserver :5	
;;

stop)
	
	/usr/local/bin/vncserver -kill :5
;;

restart)
  	$0 stop
  	$0 start
;;

*)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

Save that in a file called /etc/init.d/vncserver
chmod +x /etc/init.d/vncserver

That *should* do the trick if you are editing the ISO.

However, looks like he's referring to some saved-session stuff he has implemented and maybe this old version I got doesn't do that.
So take what I offered with a grain of salt, or maybe forget it completely. Because it doesn't look like I can do exactly what it is you were wanting - sorry.
 
Last edited:
It looks like the response from the developer indicates that any boot time scripts you want can be put into /pmagic/pmodules/scripts. I know that you can put things in init.d but maybe he said that other location for a reason.
 
It looks like the response from the developer indicates that any boot time scripts you want can be put into /pmagic/pmodules/scripts. I know that you can put things in init.d but maybe he said that other location for a reason.

I was thinking something along those lines.
However, /pmagic was not even a directory on the live system I booted - so pretty much stopped there and offered an alternative.
 
I was thinking something along those lines.
However, /pmagic was not even a directory on the live system I booted - so pretty much stopped there and offered an alternative.

Thanks so much for looking into this for me. Sorry I did not consider the purchase cost of the project.

Can I contribute a copy of the current version? PM me paypal details?
 
Last edited:
Thanks so much for looking into this for me. Sorry I did not consider the purchase cost of the project.

Can I contribute a copy of the current version? PM me paypal details?

I'll look into it more, and no paypal involved, always will to do some tech-to-tech stuff when I got the time (and if I know what to do).
 
Wow... after looking at it more I realized how easy it was.
The pmodules folder is on the root of the ISO, not the Live system.
So here is a script to place in the folder that will do what you want. This is what was being referred to you by the dev guy. Of course, you'll have to create a new bootable ISO or USB once doing so.
Code:
#!/bin/sh

# Starts the VNC server at boot on DISPLAY :1

#
# Warning, hack ahead.
# For VNC to work .xinitrc has to have the executable bit set on
# it BEFORE starting the vncserver daemon

chmod +x /root/.xinitrc

#
# Now simply start the vnc daemon.
# Using the default runtime here, flags can be added if
# necessary to define DISPLAY or NAME if need be.
# 'vncserver --help' for more on that.
# By default, vncserver will run on DISPLAY :1

/usr/local/bin/vncserver

The other option mentioned to you was adding a few lines to the OpenBox autostart file and then doing a save-session. I didn't look too much into saved sessions, but the change necessary would be to add this to the bottom of that file and then "save session" (which I'm assuming saves any changed data to a USB or network drive).
Code:
chmod +x /root/.xinitrc &
/usr/local/bin/vncserver &

If you are not comfortable with editing a file in Linux (I used vi, something else might be available) you can just do this to append those two lines to the file in question and then 'save session'.
Open a terminal (command prompt) on the Parted Magic live session and type these two lines exactly as written below:
Code:
echo "chmod +x /root/.xinitrc &" >> ~/.config/openbox/autostart.sh
echo "/usr/local/bin/vncserver &" >> ~/.config/openbox/autostart.sh

All of these things accomplish the same thing, in pretty much the same way. The script is just commented to show you what/why.

After you are booted just fire up your vncviewer of choice and connect to 192.168.1.10:1 with the password of 'partedmagic'. Of course, use the server's IP (the :1 part is the important thing).

No error checking or anything in the above methods, but should work without a hitch.
 
Last edited:
HUGE thanks and +rep to SAG for taking time out to help with this issue.

Truly mate. would have been stuffed to set this up if I had to do it on my own.

Really appreciate your generosity and helpfulness.

I owe you one ... let me know if I can return the favour :)

Jim



Wow... after looking at it more I realized how easy it was.
The pmodules folder is on the root of the ISO, not the Live system.
So here is a script to place in the folder that will do what you want. This is what was being referred to you by the dev guy. Of course, you'll have to create a new bootable ISO or USB once doing so.
Code:
#!/bin/sh

# Starts the VNC server at boot on DISPLAY :1

#
# Warning, hack ahead.
# For VNC to work .xinitrc has to have the executable bit set on
# it BEFORE starting the vncserver daemon

chmod +x /root/.xinitrc

#
# Now simply start the vnc daemon.
# Using the default runtime here, flags can be added if
# necessary to define DISPLAY or NAME if need be.
# 'vncserver --help' for more on that.
# By default, vncserver will run on DISPLAY :1

/usr/local/bin/vncserver

The other option mentioned to you was adding a few lines to the OpenBox autostart file and then doing a save-session. I didn't look too much into saved sessions, but the change necessary would be to add this to the bottom of that file and then "save session" (which I'm assuming saves any changed data to a USB or network drive).
Code:
chmod +x /root/.xinitrc &
/usr/local/bin/vncserver &

If you are not comfortable with editing a file in Linux (I used vi, something else might be available) you can just do this to append those two lines to the file in question and then 'save session'.
Open a terminal (command prompt) on the Parted Magic live session and type these two lines exactly as written below:
Code:
echo "chmod +x /root/.xinitrc &" >> ~/.config/openbox/autostart.sh
echo "/usr/local/bin/vncserver &" >> ~/.config/openbox/autostart.sh

All of these things accomplish the same thing, in pretty much the same way. The script is just commented to show you what/why.

After you are booted just fire up your vncviewer of choice and connect to 192.168.1.10:1 with the password of 'partedmagic'. Of course, use the server's IP (the :1 part is the important thing).

No error checking or anything in the above methods, but should work without a hitch.
 
HUGE thanks and +rep to SAG for taking time out to help with this issue.

Truly mate. would have been stuffed to set this up if I had to do it on my own.

Really appreciate your generosity and helpfulness.

I owe you one ... let me know if I can return the favour :)

Jim

No debts man, you owe me nothing.
Let me know if you have trouble implementing it and I'll give you a hand.
 
Back
Top