Doing updates on your Ubuntu installation sometime results in a recommended reboot(for example installing a new kernel). But how do we check if a reboot is required(if you have no access to a GUI or running Ubuntu server)?
Friday, September 9, 2011
Thursday, September 8, 2011
Learn in OOP in the most amusing way.
Having issues trying to understand all that weird concepts when it comes to OOP? Fear(!) not! This is probably the most funny and educating paper I have seen when it comes to approaching OOP.
Dont Fear The OOP.pfd
Dont Fear The OOP.pfd
[Linux] Debugging Bash scripts.
Not a fun but still a necessary task when it comes to bash scripting.
Debugging the entire script:
Debugging parts of script:
Replace the shebang with following:
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Debugging the entire script:
bash -x myScript.sh
Debugging parts of script:
set -x : activate debugging.Example:
set +x : stop debugging.
#!/bin/bashAlternative:
echo "Simple example script\n"
set -x
for i in $(seq 3)
do
echo "Hello World!"
done
set +x
echo "Done debugging!"
exit 0
Replace the shebang with following:
#!/bin/bash -xv
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Monday, September 5, 2011
[Linux] Create a random password.
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 10 | head -n 1
tr=type of characters
fold=length of password
tr=type of characters
fold=length of password
Sunday, September 4, 2011
[Linux] Simple sync/backup script.
Just polished my backup script including wake on lan. Just a simple script, but still essential to me.
#!/bin/bash
#function for syncing folders
function sync {
rsync -avrz /folders/to/sync user@host:/destination/folder
rsync -avrx /var/www/data/ ~/Dropbox/wiki/ #makes my wiki pages accessible remotely
}
#function for shutdown remote host, remember to change the rights for the poweroff command(eg. chmod u+s(Set the suid bit) poweroff)
function shutdown {
ssh user@host "poweroff"
}
#wol function, requires the wakeonlan package(on Ubuntu, apt-get install wakeonlan). Or you could use my python script(link).
function wol {
wakeonlan macaddress
}
#check if host is up(my rules: if server is up, only sync. If down start server, sync and then shutdown.
if ping -c 3 host
then
sync
else
wol
sync
shutdown
fi
exit 0
Note: Since we are using SSH for remote access it's a good idea to setup SSH login without password, follow this link
Note2: This is added to the crontab for automatic execution once a day.
Note3: I'm using hostname lookup instead of ip(which is assigned by my routers dhcp). This means that if my router suddenly changes the assigned ip(I know it's possible to reserve ip) the script is none dependend on ip. Use avahi-daemon and avahi-autoipd for this feature.
exit 0
Note: Since we are using SSH for remote access it's a good idea to setup SSH login without password, follow this link
Note2: This is added to the crontab for automatic execution once a day.
Note3: I'm using hostname lookup instead of ip(which is assigned by my routers dhcp). This means that if my router suddenly changes the assigned ip(I know it's possible to reserve ip) the script is none dependend on ip. Use avahi-daemon and avahi-autoipd for this feature.
Friday, September 2, 2011
Books - Android Development.
I'm currently struggling to learn the Android Platform. Besides from following my absolutely favorite The New Boston tutorials I also picked up this excellent book:
Beginning Android Application Development (Wrox Programmer to Programmer)
This usually my learning strategy, always use multiple sources.
Beginning Android Application Development (Wrox Programmer to Programmer)
This usually my learning strategy, always use multiple sources.
Thursday, September 1, 2011
strace - A very powerful troubleshooting tool for all Linux users.
Interesting article regarding strace
Subscribe to:
Posts (Atom)
