Archive for the ‘bash’ 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

dmidecode -t 17

rpm2cpio package.rpm | cpio –id (extracts everything in curr dir)

rsync -avopr -e ‘ssh -p ssh_port_number_only_if_different_than_22’ user@server:/(source_path) ./(destination_path)

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

tar -cvzf name.tgz dir_to_be_archived
tar -cvzf –remove-files name.tgz dir_to_be_archived
Actions (one is required):
-c create an archive
-t list an archive
-x extract files from an archive
Typically required:
-f archivename name of file archive
-z use gzip compression
-j use bzip2 compression
-v be verbose
–xattrs store SELinux and ACL properties

Supports pkzip-compatible archives
zip -r /etc

sed -i 's/match/replacement/g' file -> writes on file
sed -i.bak -> writes and backups original file

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

Can be OR’d or negated with -o or -not
find -user joe -not -group joe
find -user joe -o -user jane
find -not \( -user joe -o -user jane \)

Can match ownership by name or id
find / -user joe -o -uid 500
Can match octal or symbolic permissions
find -perm 755
matches if mode is exactly 755
find -perm +222
matches if anyone can write
find -perm -222
matches if everyone can write
find -perm -002
matches if other can write

Many find criteria take numeric values
find -size 10M
Files with a size of exactly 10 megabytes
find -size +10M
Files with a size over 10 megabytes
find -size -10M
Files with a size less than 10 megabytes
Other modifiers are available such as k for KB, G for GB, etc.

find can match by inode timestamps
-atime when file was last read
-mtime when file data last changed
-ctime when file data or metadata last changed
Value given is in days
find /tmp -ctime +10
Files changed more than 10 days ago
Can use a value of minutes
find /etc -amin -60

Commands can be executed on found files
Command must be preceded with -exec or -ok
-ok prompts before acting on each file
Command must end with Space\;
Can use {} as a filename placeholder
find -size +100M -ok mv {} /tmp/largefiles/ \;

Back up configuration files, adding a .orig extension
$ find -name ‘*.conf’ -exec cp {} {}.orig \;
Prompt to remove Joe’s tmp files that are over 3 days old
$ find /tmp -ctime +3 -user joe -ok rm {} \;
Fix other-writable files in your home directory
$ find ~ -perm -002 -exec chmod o-w {} \;
Do an ls -l style listing of all directories in /home/
$ find /home -type d -ls
Find files that end in .sh but are not executable by anyone. For each file, ask to make it executable by everyone
$ find -not -perm +111 -name ‘*.sh’ -ok chmod 755 {} \;