Posts Tagged ‘Shell’

Linux ip useful commands

ip -4 -o addr – nicely formatted list of IPv4 addresses on machine ip link show – shows the available interfaces on machine

Bulk DNS Query in Plesk

I put this command together to grab DNS information relating to all of the domains hosted on a Plesk server.  Useful if your migrating to a new server and need to know where to update the DNS zones.  This checks the nameservers but can easily be substituted with A or MX: for domain in $(mysql […]

crontab format

1 2 3 4 5 /path/to/command arg1 arg2 Where: * 1: Minute (0-59) * 2: Hours (0-23) * 3: Day (0-31) * 4: Month (0-12 [12 == December]) * 5: Day of the week(0-7 [7 or 0 == sunday]) * /path/to/command – Script or command name to schedule crontab -e = edit crontab -l = […]

chown a symlink

Not sure why I always forget this, but to chown or chmod a symbolic link rather than its target use the -h (no-dereference) flag: chown -h new_user symbolic_link_name

BASH create random password

apg -MSNCL  -m8 -x11 -n10 -E\%\\\/\|\`\<\>\+\{\}\”\’ or < /dev/urandom tr -dc A-Za-z0-9_$*?! | head -c10 Another useful implementation thanks to www.cyberciti.biz, a sample random password generator (put in your ~/.bashrc): genpasswd() { local l=$1 [ “$l” == “” ] && l=20 tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs } Run it: […]

BASH email test script

#!/bin/bash # script to send simple email # Email To ? echo “Enter Mail To” read EMAIL # Email text/message EMAILMESSAGE=”/tmp/emailmessage.txt” echo “This is an email message test”>>$EMAILMESSAGE echo | date >> $EMAILMESSAGE echo “Test”>>$EMAILMESSAGE echo “Test”>>$EMAILMESSAGE nail -v -r “support@mydomain.com” -s “Test Email” -S smtp=mysmtpserver $EMAIL < $EMAILMESSAGE #Clean up rm /tmp/emailmessage.txt

Base64 Decode using shell

perl -MMIME::Base64 -ne ‘print decode_base64($_)’ < test.in | less

Compare RPM’s on two servers

Useful if your migrating from an old server to a new one and want to check everything needed is installed. First, pull a list of RPM package by name only: rpm -qa –queryformat=’%{NAME}\n’ | sort > server.txt Once you’ve done that on both servers, just use diff to compare the two files: diff serverold.txt servernew.txt […]

Recursively change file permissions

If you chmod -R it will recursively chmod everything whether it be a file or directory. A more sensible way is: # Change directories find . -type d -exec chmod 755 {} \; # Change files find . -type f -exec chmod 644 {} \; Obviously chowning is similar: find . -type f -exec chown […]

Linux at command

A useful utility for scheduling one-off tasks. atq = view scheduled jobs at -c 7 = show command to be run in job number 7 atrm 7 = delete job number 7 at -m 08:50 2009-10-15 < updatejob = schedule a job to run the contents of updatejob or type: at -m 08:50 2009-10-15 then […]