Archive for the ‘bash scripting’ Category

syno vpn client control panel

oke, after u setup the vpn and you get it working:
enable telnet/ssh on synology box
login into synology
type ifconfig
you should see an pppx interface:

ppp0 Link encap:Point-to-Point Protocol
inet addr:192.168.1.44 P-t-P:192.168.1.99 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1396 Metric:1
RX packets:1819 errors:0 dropped:0 overruns:0 frame:0
TX packets:1372 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:1694061 (1.6 MiB) TX bytes:236202 (230.6 KiB)

you need the P-t-P ip: in this case is 192.168.1.99

vi /etc/ppp/ip-up

add at the end of file:

#added for vpn routes
case "${IPREMOTE}" in
192.168.1.99)
ip ro add 1.2.3.4/24 dev ${IFNAME}
ip ro add 2.3.4.0/24 dev ${IFNAME}
;;
esac

restart vpn from control panel:
you should see already the new routes:

nas> ip route show
192.168.1.99 dev ppp0 src 192.168.1.44
|ip of vpn server| via |default gw| dev eth0 src |ip of syno|
|local subnet|/24 dev eth0
1.2.3.4/24 dev ppp0
2.3.4.0/24 dev ppp0
default via |gateway| dev eth0

Backup the partition table

$ sfdisk -d /dev/sda > /tmp/partitions.sda

Partition the disk

$ fdisk /dev/sda

Restore partition table after major mistake

$ sfdisk /dev/sda < /tmp/partitions.sda

Update /proc/partitions

$ partprobe /dev/sda

sort [options] file(s)
Common options
-r performs a reverse (descending) sort
-n performs a numeric sort
-f ignores (folds) case of characters in strings
-u (unique) removes duplicate lines in output
-t c uses c as a field separator
-k X sorts by c-delimited field X
Can be used multiple times

Display specific columns of file or STDIN data
cut -d: -f1 /etc/passwd
grep root /etc/passwd | cut -d: -f7
Use -d to specify the column delimiter (default is TAB)
Use -f to specify the column to print
Use -c to cut by characters
cut -c2-5 /usr/share/dict/words

You may check first what is the path of sendmail:
whereis sendmail or php -i | grep sendmail
move /usr/sbin/sendmail to something like /usr/sbin/sendmail.or
vi /usr/sbin/sendmail
put the code below:

#!/usr/bin/perl
# use strict;
use Env;
my $date = `date`;
chomp $date;
open (INFO, ">>/var/log/formmail.log") || die "Failed to open file ::$!";
my $uid = $>;
my @info = getpwuid($uid);
if($REMOTE_ADDR) {
print INFO "$date - $REMOTE_ADDR ran $SCRIPT_NAME at $SERVER_NAME \n";
}
else {
print INFO "$date - $PWD - @info\n";
}
my $mailprog = '/usr/sbin/sendmail.or';
foreach (@ARGV) {
$arg="$arg" . " $_";
}
open (MAIL,"|$mailprog $arg") || die "cannot open $mailprog: $!\n";
while (<STDIN> ) {
print MAIL;
}
close (INFO);
close (MAIL);


chmod a+x /usr/sbin/sendmail
touch /var/log/formmail.log
and chmod 777 /var/log/formmail.log

that should be all.

$ cat /etc/passwd | awk -F: '{print $1}' | while read line; do echo $line; crontab -l -u $line; done

http://www.linuxscrew.com/2009/12/21/best-of-linux-cheat-sheets/

ls | while read line; do x=$(echo $line |egrep -o .*mp3); mv $line $x ;done

#!/bin/sh
SERVICE='named'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
cat /dev/null
else
echo "$SERVICE is not running... starting"
/etc/init.d/$SERVICE restart | mail -s "$SERVICE restarted" email@domain.tld
fi

p.s. do not name the script as the service 🙂