Posts

Showing posts with the label Linux

How to restart networking without DHCP RELEASE on Ubuntu

On Ubuntu systems, there is no more networking service restart option, so users are forced to do ifdown and ifup. But  ifdow n  by default do a DHCPRELEASE causing systems to potentially change IPs on ifup. This would not be a very appreciated sideaffect with automated systems where IPs could change during the lifetime of the system. Following script allows you to restart networking without actually do a DHCPRELEASE, (to avoid the DHCPRELEASE create temporary interfaces with all interfaces set to static and  bring down interfaces using that file, but use the original file to do the bring up the interfaces) # cat ifdownup.sh pkill dhclient && \ sed 's/dhcp/manual/' /etc/network/interfaces > /tmp/interfaces && \ for intf in `cat /etc/network/interfaces | grep inet | cut -d ' ' -f 2`; \ do ifdown $intf -i /tmp/interfaces && ifup $intf; done​

Redirect both stdout and stderr to dev null using > /dev/null 2>&1 for linux commands and scripts

/ tmp ( ) $ cat out_err_redirect_test . sh echo message to stdout echo message to stderr > & 2 / tmp ( ) $ bash out_err_redirect_test . sh message to stdout message to stderr # Message to stdout is redirected to dev null / tmp ( ) $ bash out_err_redirect_test . sh > / dev / null message to stderr # Message to stderr is redirected to dev null / tmp ( ) $ bash out_err_redirect_test . sh 2 > / dev / null message to stdout # Message to stderr and stdout is redirected to dev null / tmp ( ) $ bash out_err_redirect_test . sh > / dev / null 2 > / dev / null # Messaged to stdout is redirected to dev null , and stderr to configured stdout ( implies dev null ) / tmp ( ) $ bash out_err_redirect_test . sh > / dev / null 2 > & 1 # Message to stderr is redirected to stdout ( screen ) and stdout to dev null / tmp ( ) $ bash out_err_redirect_test . sh 2 > & 1 > / dev / null message to stderr

To speed up accessing files on nfs shares on a ubuntu machine ...

To enable nfs caching on ubuntu, sudo apt-get install cachefilesd sudo sed -i 's/nfs rw/nfs fsc,rw/' /etc/fstab service restart cachefilesd To use tmpfs instead of disk cache use this after making sure the runner has atleast 12G of memory, mount | grep fscache || mount -t tmpfs -o size=8192m tmpfs /fscache ls /fscache/disk0 || dd if=/dev/zero of=/fscache/disk0 bs=1M count=8191 sleep 15 ls /fscache/disk0 && echo 'y' | mkfs.ext4 /fscache/disk0 mount /fscache/disk0 /var/cache/fscache -t ext4 service cachefilesd restart

FD column in linux command lsof means a lot ....

lsof gives a ton of information about the files and devices that are open on a system. FD has always wondered me with some wierd numbers/characters. Atlast I bothered to look at it for knowing whether tcpdump has started or not to sniff the device and realized it gives details about the what kind of device/file is opened and the permissions etc. From the man page,        FD         is the File Descriptor number of the file or:                        cwd  current working directory;                        Lnn  library references (AIX);                        err  FD information error (see NAME column);                        jld  jail directory (FreeBSD);                        ltx  shared library text (code and data);                        Mxx  hex memory-mapped type number xx.                        m86  DOS Merge mapped file;                        mem  memory-mapped file;                        mmap memory-mapped device;                        pd   parent directory;     ...

Want a fast and temporary file system on linux?

Just use a tmpfs/ramfs and a cron job continously backing up data from  this to a non-volatile storage. mount -t tmpfs -o size=1024m tmpfs /tmp Generally, I use this for logs on virtual machines, as sometimes the  disk is very slow due to multiple VMs running off the same disk. Also,  this has the advantage of not wearing out the disk, which might have  more important/persistent data.

Fighting the zombies out of your linux system ...

I had tough time to figure out that zombies are invading my linux box, here's the powerful one-liner to kill them all :) kill -9 `ps -ef | grep defunct | cut -d ' ' -f 3`

Tip to organize photos by date taken as folder name

exiftool -d "./%Y-%m-%d/%%f.%%e" "-filename<createdate" *.JPG If you don't like the default file names which are mostly like IMG_0001.JPG in the DSLR cameras, you can just use the time stamp using the following command, exiftool -d "./%Y-%m-%d/IMG_%Y%m%d_%H%M%S_%%-c.%%e" "-filename<createdate" *.JPG %%-c will kick in the counter for your sub-second shots.