Contents

Linux Tips and Howtos

Linux tips and Howtos that I gathered over the years. Some of them might be old, so do your research. Some of them can be destructive, so be careful. Some of these saved me allot of time and disk space. Enjoy

Tar/ssh files example:

1
     tar zcvf - /u01/ | ssh root@10.10.10.31 "cat > /OVS/backup/erpprd_apps_1450_16022011.tar.gz"

and to restore

1
2
     cd /youlocation
     ssh root@10.10.10.31 "cat /OVS/backup/erpprd_apps_1450_16022011.tar.gz" | tar zxvf -

Tar/ssh sparse files example:

Example 1:

1
     tar -czSvf - 0004fb0000030000a5e8ff0ea5160ada/VirtualMachines/0004fb0000060000b3bd86f6aa8805cb/vm.cfg 0004fb0000030000a5e8ff0ea5160ada/VirtualDisks/eggy_osdisk.img 0004fb0000030000a5e8ff0ea5160ada/VirtualDisks/eggy_data_u01.img | ssh user@10.10.10.156 'cat - > /OVS/Repositories/0004fb00000300003e4055947747bd7f/eggy.tar.gz'

Example 2:

1
     tar -czSvf - backup/ oracle/ | ssh root@eggy 'tar -C /mnt/disk/ -zSvxf -'

To create a sparse file on a Linux host

You can run dd with a count size of zero (this tells dd not to write any data to the file), and then use the seek option to extend the file to the desired size:

1
     bash$ dd if=/dev/zero of=xen-guest.img bs=1 count=0 seek=8G

Once the sparse fie is created, you can use dd to verify how much space is allocated to it:

1
2
3
4
5
     bash$ du -sh xen-guest.img
     0 xen-guest.img

     bash$ du -sh --apparent-size xen-guest.img
     8.0G xen-guest.img

To create more loop devices on openSuse

vi /etc/modprobe.d/99-local.conf

1
     options loop max_loop=20

Compressing apps and db files and splitting in 2G files

1
     bash$ tar cvf - test|gzip|split -b2000m - /disk/test.tar.gz.split

Testing a tar.gz file

1
     gunzip < dep_apps_all.tar.gz | tar tvf -

To rescan emulex bus for new luns

1
     echo "- - -" > /sys/class/scsi_host/hostX/scan

Telegram troubleshooting

Command line string to send text to a user or group

1
    curl 'https://api.telegram.org/botxxxxxxxxx:AAGApzqgDVY5x8lGyOMgUHzPEtjuqaCoY7s/sendMessage' -d chat_id='-xxxxxxxxx' -d text='This is a test messages'

routeing ip traffic to localhost

1
    iptables -t nat -I OUTPUT --dst 5x.2x.2xx.1xx -p tcp --dport 3306 -j REDIRECT --to-ports 3306

check for process threads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
    ps -efL|grep -i prome| awk '{print $2}'|sort|uniq -c
    6113 13751
      1 15899
    267 26295
    211 31630
    209 32402
    200 54246
    264 7594

    ps -eLf | grep 13751 | wc

Restore broken LVM VG

Copy backup or archive file to root edit file and look for [missing]. Normally backup can be found at /etc/lvm/ Use below commands with care, it can brake your OS, if you don’t know what you are doing.

1
2
    vgcfgrestore --list centos_os
    vgcfgrestore -f /etc/lvm/archive/[backup_file] centos_os

Allowing user to use systemctl to manage services

Entry in your /etc/sudoers file:

1
2
3
     User_Alias ADMINS_SYS = auser
     Cmnd_Alias ADMINS_CMD = /bin/systemctl start httpd, /bin/systemctl stop httpd, /bin/systemctl reload httpd, /bin/systemctl restart httpd, /usr/bin/systemctl status httpd
     ADMINS_SYS      ALL = NOPASSWD: ADMINS_CMD

Always check your haproxy.cfg file

haproxy -c -V -f /etc/haproxy/haproxy.cfg