Archive for the ‘Linux’ Category

Linux hardware clock

You can use hwclock to synchronise the system clock with the hardware clock: hwclock –show read hardware clock and print result –set set the rtc to the time given with –date –hctosys set the system time from the hardware clock –systohc set the hardware clock to the current system time

Check RAM type without opening server

You can use dmidecode in Linux to check various hardware specs such as CPU / memory without having to physically open or power down the server. For example to see the RAM needed: dmidecode –type memory SMBIOS 2.5 present.

Ping an entire network / netblock

You can use fping to ping a netblock to see which hosts are alive: fping -g You could also put ping into a loop, but the output is less than useful: for i in {1..254}; do ping -c1 192.168.1.$i; done nmap is also a handy solution and can provide much more host information if […]

Basic AWK usage in BASH

To print a field from a file (-F is the field separator and $ is the number of the field to print): awk -F':’ ‘{ print $1 }’ /etc/passwd or awk -F':’ ‘{ print $1 $3 }’ /etc/passwd or awk -F':’ ‘{ print “username: ” $1 “\t\tuid:” $3″ }’ /etc/passwd

BASH – making tab completion case insensitive

This is very lazy, but comes in handy for example if your browsing a Windows mount with random uppercases in file/folder names. Add: make your tab completion case insensitive To your $HOME/.inputrc file (create the file if it doesn’t exist).  Alternatively you can make this userwide by adding it to /etc/inputrc . You might need […]

Using mod_proxy to avoid DNS propagation during site migration

There are a number of ways to migrate a site to a new server, whilst avoiding downtime or data concurrency issues. For a highly dynamic site, generally I would edit the old and new site connection strings to both use the same database during switchover.  mod_proxy is a useful method perhaps if a new version […]

Identifying apache process usage

When apache is running with php as an apache module rather than as a CGI, all processes will run as the apache user.  This makes it a little tricky on a busy multi-site box to identify which sites are using resources and keeping sessions open.  This little command will identify the working directory that the […]

Mounting Windows drives and shares in Linux

The following have come in handy for mounting a Windows share on a Linux computer: mount -t cifs -o username=user,password=password,umask=000 //winbox/winshare /mnt/home/ or smbmount //winbox/winshare /mnt/home/ -o username=user,password=password,rw An example of mounting a local NTFS partition held on the same machine: ntfsmount /dev/sda2 /mnt/windows -o umask=0002,silent

Yum Automatic Updates

You can install yum-cron to automatically download and install all available updates: yum install yum-cron chkconfig –list | grep yum – should show that the service is disabled chkconfig yum-cron on service yum-cron start Job Done – it will now check for and apply updates every night.  If its business critical solution though its probably […]

Random integers in BASH

Never really had a need for it before in BASH, but the following formula allows you to create random integers between two values: rnumber=$(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min)) Useful for example to create random passwords that have a length within a set range. < /dev/urandom tr -dc A-Za-z0-9_$*?!.:=@#% | head -c$((RANDOM %4 +8))