Some apt and tasksel magic. If you want to have an apache server with mysql and php ready to work in ubuntu is as easy as:
sudo apt-get install tasksel
sudo tasksel install lamp-server
Some apt and tasksel magic. If you want to have an apache server with mysql and php ready to work in ubuntu is as easy as:
sudo apt-get install tasksel
sudo tasksel install lamp-server
Prefered method if ssh is available.
Another way, if you have SSH:
rsync -aE -e ssh directory user@hostB:target_dir
or from hostB
rsync -aE -e ssh user@hostA:directory target_dir
You can also use the z (--compress) switch to rsync if network throughput is an issue.
What this script does is, check the gateway mac address to find out if you are within your lan or in a different place. If at home, mount a share as normal. If away, mount that share as a ssh file system.
#!/bin/bash
gateway=$(ip route show 0.0.0.0/0 | awk '{print $3}')
mactest=$(arp -n -a $gateway | awk '{print $4}')
targetmac="XX:XX:XX:XX:XX:XX"
homeup="mount -t cifs -o username=USER,password=PASSWORD //SERVER/SHARE /mnt/remote"
awayup="sshfs my.dyndns.tld:/path/to/share /mnt/remote"
down="umount -l /mnt/remote"
if [ $mactest==$targetmac ]
then
case "$2" in
up)
$homeup
;;
down)
$down
;;
esac
else
case "$2" in
up)
$awayup
;;
down)
$down
;;
esac
fi
exit $?
Use find to locate files over a criteria size and format output with awk. Changing value of NF variable you change fields separator
find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $NF ": " $5 }'
With this command you can tunnel your communications if you set software to connect to localhost 127.0.0.1 port 9999
ssh -D 9999 [email protected]
Sometimes when you connect to a ssh server whois host key has changed, ssh client warns you about it. If you want to ignore that advice use StictHostkeyChecking no option.
ssh -o 'StrictHostKeyChecking no' [email protected]
Use dpkg-reconfigure to change time zone on Debian
dpkg-reconfigure tzdata
Quick command to dump all tables matching a like pattern. In the example drop tables option is added with xargs.
mysql $DB -u$USERNAME -p$PASSWORD -e 'show tables like "$LIKE%"' | grep -v Tables_in | xargs mysqldump --add-drop-table $DB -u$USERNAME -p$PASSWORD
A
if [ -d ~/.ssh ]; then
# Touch files we expect to exist
if [ ! -e ~/.ssh/config ]; then touch ~/.ssh/config; fi
if [ ! -e ~/.ssh/known_hosts ]; then touch ~/.ssh/known_hosts; fi
# Parse ~/.ssh/known_hosts and ~/.ssh/config to find hosts
for x in `sed -e ’s/[, ].*//’ ~/.ssh/known_hosts; awk ‘/^Host [^*?]+$/{print $2}’ ~/.ssh/config`; do
# Don’t override commands
type $x > /dev/null 2>&1 && continue
alias $x=â€ssh $xâ€
# Remove the domainname
y=${x/.*/}
if [ “$y” != “$x” ]; then
if ! type $y > /dev/null 2>&1; then
alias $y=â€ssh $xâ€
fi
fi
# Remove prefix. Add prefixes you want removed here
y=${y/pf1-/}
y=${y/pf2-/}
if [ “$y” != “$x” ]; then
if ! type $y > /dev/null 2>&1; then
alias $y=â€ssh $xâ€
fi
fi
done
fi
Quick script to delete matching emails in sendmail queue. Really usefull when an account has been hacked and you have thounsands of spam emails in the queue.
#!/bin/sh
cd /var/spool/mqueue
for i in `grep -sl "
do
j=`ls -1 "$i" | sed 's/qf\(.*\)$/df\1/'`
echo "Deleting $i ($j)"
rm $i $j
done