You can do that using mpack
mpack -s "This is the subject" -d body.txt attachment.zip [email protected]
You can do that using mpack
mpack -s "This is the subject" -d body.txt attachment.zip [email protected]
I have a Sky Hub router, the SR102 (black). Previously I had the white version as well.
Nice routers, pretty stable, but badly locked. You can change the SID of your wifi, change the password… not either sure if you can do a proper port forwarding. So… perfect for my mum, but a pain for whoever wants a little bit of extra control.
I had already an ASUS RT-N16 with DD-WRT firmware so I used the DMZ function on the Sky router to have some sort of “link” of the public IP of my broadband directly on the WAN interface of the router. In this way it’s like that is my ASUS router that does the connection and I can play as freely as I want, without caring much about the Sky router.
However, it happens that sometimes you need to give a full reboot to the main Sky router. And maybe do this automatically or via command line/script. And here it’s when things are getting more complicated.
The Sky Hub router allows you to reboot it via HTTP. Using the DMZ anyway will bypass the router itself and forward all the requests to the ASUS router. Also, I have never liked the idea to expose my router management page to the Internet, but I rather prefer to connect via SSH on a Raspberry Pi and issue commands from the terminal (telnet/ssh).
So, beside my multiple attempts to find a way to curl the button on the page, I had to find an alternative way to makes this happen. Of course, it didn’t help either to call the Sky Helpline asking if there was a remote possibility to have telnet enabled.
After a bit of talks on Facebook with some friends, here the solution: Remote Controlled Sockets with Pi-mote
Yes. If I can’t reboot from inside, let’s to that from outside!
The process was pretty straight forward.
First of all, I had to turn off my Raspberry Pi, and plug the “little green piece of board” as mentioned in here
After that, I’ve turned the pi on again, and installed the required packages. Happily I found that there is now the python library available for energenie, so I have installed them as well, making my life easier 🙂
apt-get install python-rpi.gpio python-pip pip install energenie
Once done, I have created these two basic script and I have run one a time, to configure the socket plugs.
Make sure to plug the ONE SOCKET PLUG A TIME and run the relative script.
You can find more information in the previous PDF, but these sockets learn who they are based on which commands they are receiving during the learning mode (enabling keeping the green button pressed for about 5 seconds when switched off). So if you run the first script with both plugs connected and in learning mode, they will do exactly the same, and unless you want to control two sockets at the same time, better to follow the instructions 🙂
Script to configure the first socket:
from energenie import switch_on, switch_off from time import sleep # turn the first plug socket ON and then OFF switch_on(1) sleep(5) switch_off(1)
Script to configure the second socket:
from energenie import switch_on, switch_off from time import sleep # turn the second plug socket ON and then OFF switch_on(2) sleep(5) switch_off(2)
And now, my simple script to make… “the magic”: plugs.py
from energenie import switch_on, switch_off from time import sleep import sys if len(sys.argv) == 1: print "Use:\n# python plug.py <plug_ID> <ON/OFF>\ne.g. # python plug.py 1 ON" exit(1) else: plug = sys.argv[1] status = sys.argv[2] if status.lower() == 'on': switch_on(int(plug)) else: switch_off(int(plug))
You can use this script to control any sockets (up to 4 – hardware limitation).
And here a bash wrapper (I’m not really good in python sorry) that calls plugs.py and restart the router: restart_sky_router
#!/bin/bash # This script requires plug.py script if [ "$EUID" -ne 0 ] then echo "Please run as root or use 'sudo'" exit fi echo "Switching OFF and then ON the physical socket" # Uses ENERGENIE Radio controlled Sockets python plug.py 1 off sleep 10 python plug.py 1 on
Now, I can have my Nagios system to check for the speed as documented here and eventually issue restart_sky_router script to see if it fixes the issue. Or simply be able to have a command to integrate in your scripts!
Bash script that extract the router speed.
#!/bin/bash # Broadband Speed within limits Download 14000 and Upload 750 ROUTER=<router_ip> USER=<router_username> PASS=<router_password> # Download Link speed DL=14000 # Upload Link speed UL=750 SPEED=($(wget -qO- http://$ROUTER/sky_router_status.html --user=$USER --password=$PASS | awk -F "'" '$0 ~ /Modemstat\[0\]/ {print $2, $4}')) if [[ ${SPEED[0]} -lt $DL || ${SPEED[1]} -lt $UL ]] ; then exit 2 else echo "Broadband Speed within limits Download ${SPEED[0]} and Upload ${SPEED[1]}" exit 0 fi
This can be integrated in Nagios to send an alert if the speed drops.
This setup is suggested for TESTING purposes only. In a production environment please verify performances.
Create a separate network and map IP/servers' names in /etc/hosts Append to /etc/hosts # GlusterFS 192.168.3.5 gfs01 192.168.3.6 gfs02 >> On BOTH nodes: yum update wget -P /etc/yum.repos.d http://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/glusterfs-epel.repo yum -y install parted lvm2 xfsprogs glusterfs glusterfs-fuse glusterfs-server grep ^exclude /etc/yum.conf [root@gfs01 sysconfig]# grep ^exclude /etc/yum.conf exclude=gluster* (in [main] section) parted -s -- /dev/xvdb mktable gpt parted -s -- /dev/xvdb mkpart primary 2048s 100% parted -s -- /dev/xvdb set 1 lvm on partx -a /dev/xvdb pvcreate /dev/xvdb1 vgcreate vggfs01 /dev/xvdb1 lvcreate -l 100%VG -n gbrick1 vggfs01 mkfs.xfs -i size=512 /dev/vggfs01/gbrick1 echo '/dev/vggfs01/gbrick1 /data/gluster/gvol0 xfs inode64,nobarrier 0 0' >> /etc/fstab mkdir -p /data/gluster/gvol0 mount /data/gluster/gvol0 mkdir -p /data/gluster/gvol0/brick1 /bin/systemctl start glusterd.service /bin/systemctl status glusterd.service systemctl enable glusterd.service >> On NODE2 gluster peer probe gfs01 gluster peer status gluster pool list >> On NODE1 gluster peer probe gfs02 gluster peer status gluster pool list gluster volume create gvol0 replica 2 transport tcp gfs01:/data/gluster/gvol0/brick1 gfs02:/data/gluster/gvol0/brick1 gluster volume start gvol0 gluster volume info gvol0 gluster volume set gvol0 performance.cache-refresh-timeout 30 gluster volume set gvol0 performance.io-thread-count 32 gluster volume set gvol0 performance.cache-size 1073741824 gluster volume info gvol0 ============================================================ TO MOUNT - Fuse (HA) => nodes need to be connected to the same Cloud Network Append to /etc/hosts # GlusterFS 192.168.3.5 gfs01 192.168.3.6 gfs02 yum -y install glusterfs glusterfs-fuse modprobe fuse echo 'gfs01:/gvol0 /mnt/gluster/gvol0 glusterfs defaults,backupvolfile-server=gfs02,_netdev 0 0' >> /etc/fstab mkdir -p /mnt/gluster/gvol0 mount /mnt/gluster/gvol0 ========================================================== It seems that Debian 7 cannot have GlusterFS 3.7 but only from Debian 8. http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.0/Debian/jessie/ ========================================================== Extra source: http://matty.digital/gluster Extra commands # gluster volume remove-brick gvol0 gfs02:/data/gluster/gvol0/brick1 force # gluster peer detach gfs02 # gluster peer detach gfs01 # gluster peer probe gfs01
Check branch
git branch <name new branch>
Show changes after your last commit
git diff
rollback to previous change (specific file) to the latest commit
git checkout -- testfile
Delete branch
git branch -D <branch name>
Push new branch to the origin (my ‘git space’)
git push -u origin <branch name>
Restore file from upstream
git checkout upstream/master -- <filename>
Commit changes in one single line
git commit -a -m "comment"
If you want to merge the recent changes committed on the master branch into your dev branch
git checkout dev # gets you "on branch dev" git fetch origin # gets you up to date with origin git merge origin/master
If you want to reset ALL from the version ‘on the web’
git fetch origin git reset --hard origin/<branch>
Check containers
# docker ps -a
Connect to a container
# docker start <ID> # docker attach <ID>
Exit from a container
-> type 'exit'
Remove all of Docker containers:
docker stop $(docker ps -a -q) docker rm $(docker ps -a -q)
DNS queries can be an issue on Cloud infrastructure, where SaaS are generally configured using FQDN instead of IP. This means that every time your application needs MySQL or Redis or any of the Platform/Software as a service, a DNS query will be issued.
Sometimes this could hammer the local DNS and service providers might block your DNS traffic.
To minimise this, you could use nscd to cache the DNS queries and reduce the traffic to the local DNS servers.
>> Test if port 53 has been blocked tcpdump -vvv -s 0 -l -n port 53 >> Check what is currently cached nscd -g (and check hosts cache) >> Configuration file grep -v "^#" /etc/nscd.conf (leaving only 'hosts' details) server-user nscd debug-level 0 paranoia no enable-cache hosts yes positive-time-to-live hosts 3600 negative-time-to-live hosts 20 suggested-size hosts 211 check-files hosts yes persistent hosts yes shared hosts yes max-db-size hosts 33554432
/etc/apt/sources.list #Infinality Fonts deb http://ppa.launchpad.net/no1wantdthisname/ppa/ubuntu saucy main apt-get install fontconfig-infinality cd /etc/fonts/infinality/ bash infctl.sh setstyle chose 3 (i.e. linux). In /etc/profile.d/infinality-settings.sh --> search for “USE_STYLE” or scroll (around line 710) till you see the option to set the style => USE_STYLE=”UBUNTU” Settings -> Appearance. Tick the checkbox to Enable anti-aliasing Set Sub-pixel order to RGB Set Hinting to Slight ====================================== Personally installed before also: cabextract fonts-liberation ttf-mscorefonts-installer ====================================== Other fonts: 1) Install pretty fonts (you'll need non-free for mscorefonts): apt-get install ttf-dejavu ttf-liberation ttf-mscorefonts-installer xfonts-terminus 2) dpkg-reconfigure fontconfig-config, select Autohinter, Automatic and No 3) dpkg-reconfigure fontconfig 4) Restart Xorg 5) Gnome-specific (these are largely personal preferences): System -> Preferences -> Appearances -> Fonts: Enable 'Best Shapes', Details -> Dots per Inch: 110, Smoothing -> Grayscale ======================================
apt-get purge nova-client apt-get update && apt-get upgrade Used this script to re-install nova-agent: https://github.com/rackerlabs/openstack-guest-agents-unix/blob/master/tools/nova-agent-builder.sh >> extract the tar and ./install.sh sed '1i### BEGIN INIT INFO\n# Provides: Nova-Agent\n# Required-Start: $remote_fs $syslog\n# Required-Stop: $remote_fs $syslog\n# Default-Start: 2 3 4 5\n# Default-Stop: 0 1 6\n# Short-Description: Start daemon at boot time\n# Description: Enable service provided by daemon.\n### END INIT INFO\n' /usr/share/nova-agent/1.39.1/etc/generic/nova-agent > /usr/share/nova-agent/1.39.1/etc/generic/nova-agent.lsb cp /usr/share/nova-agent/1.39.1/etc/generic/nova-agent.lsb /etc/init.d/nova-agent chmod +x /etc/init.d/nova-agent service xe-linux-distribution stop service xe-linux-distribution start service nova-agent start # ps aux | grep nova root 7874 0.0 0.7 143984 7464 ? Ssl 09:02 0:00 /usr/sbin/nova-agent -q -p /var/run/nova-agent.pid -o /var/log/nova-agent.log -l debug /usr/share/nova-agent/nova-agent.py root 7890 0.0 0.0 11980 928 pts/0 S+ 09:03 0:00 grep --color=auto nova Sources: http://www.syntheticworks.com/rackspace-cloud/linux-rackspace-cloud/all-about-nova-agent-linux/ https://github.com/rackerlabs/openstack-guest-agents-unix/blob/master/tools/nova-agent-builder.sh http://bootrackspacecom.readthedocs.org/en/latest/nova_agent/
There is an agent called “nova-agent” which runs on all Rackspace cloud virtualised servers. This agent handles all communication between the hypervisor and guest OS, and is used for decloning.
Because it is used during decloning, it owns the /etc/hosts file and many files related to DNS and networking (/etc/resolv.conf , /etc/sysconfig/network-scripts/ifcfg-eth0 ,etc)
It is unlikely, but possible, that the host reboot triggered nova-agent to reset your hosts file.
To prevent nova-agent from overwriting your files, you can change the attributes of the file using the following command:
# chattr +i /etc/hosts
This will make the file unwriteable even to root! To remove this restriction, use the following:
# chattr -i /etc/hosts