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: P-t-P: Mask:
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

vi /etc/ppp/ip-up

add at the end of file:

#added for vpn routes
case "${IPREMOTE}" in
ip ro add dev ${IFNAME}
ip ro add dev ${IFNAME}

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

nas> ip route show dev ppp0 src
|ip of vpn server| via |default gw| dev eth0 src |ip of syno|
|local subnet|/24 dev eth0 dev ppp0 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:

# 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);
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

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

if ps ax | grep -v grep | grep $SERVICE > /dev/null
cat /dev/null
echo "$SERVICE is not running... starting"
/etc/init.d/$SERVICE restart | mail -s "$SERVICE restarted" email@domain.tld

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