Everyone knows one of the beauties of Linux (and FOSS in general) is the ability to delve in and change functionality for your own requirements. I was having an issue where a standard “poweroff” or “halt” was not shutting the computer down properly, so I needed to write my own scripts to replace them.
On Ubuntu /sbin/poweroff and /sbin/halt are symlinks to /sbin/reboot which is a binary (on debian reboot and poweroff symlink to halt), but the binary is aware of which command is being called, and acts accordingly. This means if you replace one of the symlinks with a script which in turn calls the binary, it will not necessarily perform the action you want (i.e. it will reboot rather than halt or poweroff).
On Ubuntu I solved this problem by creating a /sbin/local directory, copying the binary into there and creating local symlinks.
cp /sbin/reboot /sbin/local/reboot
ln -s reboot /sbin/local/poweroff
ln -s reboot /sbin/local/halt
I was then free to replace the /sbin/poweroff, /sbin/halt and /sbin/reboot scripts with my own custom scripts, which were able to call the scripts in /sbin/local and would execute those correctly.
Bash is not exactly brilliant at performing numerical calculations. Recently I’ve required the need to see how many people are currently logged in on the terminal servers through NX. Now, if people are logged in via standard SSH, then it’s quite easy to count:
who | wc -l
However, if you want to perform a line count of the NX list, you have 6 lines at the top which are not part of the count. In order to perform this subtraction, we need to do a calculation. To do this in bash we use a $(()):
echo $((2 + 2))
So, if we were to use this when performing the command on nxserver, this is how it would look in the end:
echo $(($(/usr/NX/bin/nxserver --list | wc -l) - 6))
Or, if you’re not running this script as root (and using sudo):
echo $(($(sudo /usr/NX/bin/nxserver --list | wc -l) - 6))
I’ve just updated the FreeNX install script to download and install the latest version of the NX Client from NoMachine. If you have used the previous version of this script, then you can just execute this version and it will automatically update your NX Client.
Download the latest version from here.
I have introduced a Labs section to my site. This section will contain on going projects, applications and scripts which I am working on for people to play with a leave feedback.
At the same time I have added a script to the section, which automatically downloads and installs FreeNX onto an Ubuntu system. The script and further details are available from here.