Μετάφραση στα ελληνικά του locate για το back-end του Croogo. Διαθέσιμο στο GitHub.
Tag: script
Remote cPanel backup via FTP
Here is the scenario:
– Domain that needs to be backed up (public_html, mail, database).
– Only access available via cPanel and FTP.
– Need automated daily full backup.
Solution:
– Take full backup on server and compress its contents (cronjob on remote server)
– Download via FTP the compressed file to the local machine (cronjob on local machine).
– Delete compressed file.
There might be tools that do this, although I didn’t come across any while looking on the web. I implemented a simple solution based on bash scripts that gets the task done.
– backup.sh: Goes on the remote server to run as a cronjob.
– ftp.sh: Runs locally (on the machine that will store the backup) as a cronjob.
– .netrc: Defines the FTP account details (stored in /home/$user/.netrc)
Assigning HTML “rel” attribute to all page images
Very briefly, in a CakePHP app, I want to apply the lightbox script on all the images that link from a thumbnail to a larger image. If there are more than two, I want them to appear as a lightbox group. I don’t want the user to mess with TinyMCE and HTML, therefore I automatically apply the rel attributed for every single image in a page that is a hyperlink. The following PHP bit is added in app/Plugin/Nodes/View/Nodes/view.ctp. With some small changes it can be used for any PHP compatible web site.
$body = $this->Nodes->body(); if (strpos($body, "img")) { $pattern ="/<a(.*?)href=('|\")(.*?).(jpeg|jpg|png)('|\")(.*?)>/i"; $newLink = '<a$1href=$2$3.$4$5 rel="lightbox[group]".$6>'; echo preg_replace($pattern, $newLink, $body); } else { echo $body; }
Converting OS X .plist to XML
The failure of my MacBook Pro seems that it didn’t cost much in terms on data loss, actually all the really crucial data were there. There are though some bits here and there that need to be moved over to my Linux box. One of the most important for everyday use the was the feed list for my RSS Aggregator. I was using the elegant, nice and simple NewsFire which uses binary plists (XML-like) for storing the feed list and I was never bothered exporting the feed list to OPML. The plist command in OS X can convert the .plist file into a .xml file, however I had no other Mac to do this operation or copy over the plist and export in OPML from there. Therefore I had to find a workaround for getting the plist working on RSSOwl or Liferea. Found the Perl plutil for Linux which converted the binary plist to standard XML. RSSOwl managed then to import the XML with all the blogs’ feeds as on NewsFire.
Regarding liferea, it wouldn’t import the XML file as it wasn’t proper OPML. But since RSSOwl imported the XMl file, I exported the feed list as OPML, which would be imported into Liferea or any other application.
Shell script for NITROX calculations
The following script was developed for providing quick calculations over NITROX diving. It provides an interactive menu for the following calculations:
1 – Maximum Operational Depth (MOD)
2 – Operational Depth (OD)
3 – Best mix
4 – Equivelant Air Depth (EAD)
5 – Nitrogen percentage compared to Air
6 – Oxygen partial pressure (PO2)
7 – Central Nervous Systems Toxicity (CNS)
8 – Absolute pressure
############################################################################ # Copyright (C) 2011 Panagiotis Kritikakos <panoskrt@gmail.com> # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################ #!/bin/bash disclaimer() { echo " ======================================================= Every individual diver is responsible for planning and conducting dives using SCUBA equipment up to the trained and certified qualification he or she holds. The creator of this program does not have any responsibility for symptoms of Decompressions Sickness when the suggested values of this program are used for conducting a dive. ======================================================== " } mod(){ echo -n "NITROX mix: "; read mix MOD=`echo "scale=2; (((1.6/$mix)*10)*100)-10" | bc` echo " MOD for $mix NITROX: $MOD" } od(){ echo -n "NITROX mix: "; read mix OD=`echo "scale=3; (((1.4/$mix)*10)*100)-10" | bc` echo " OD for $mix NITROX: $OD" } bestmix(){ echo -n " Depth: "; read depth BESTMIX4=`echo "scale=2; 1.4/(($depth/10)+1)" | bc` BESTMIX6=`echo "scale=2; 1.6/(($depth/10)+1)" | bc` echo " Best mix for 1.4 PO2: $BESTMIX4" echo " Best mix for 1.6 PO2: $BESTMIX6" } ead(){ echo -n " Depth: "; read depth echo -n " NITROX: "; read nitrox EAD=`echo "scale=2; ((((1-($nitrox/100))*4)/0.79)-1)*10" | bc` echo " EAD for $depth MSW and NITROX $nitrox: $EAD" } compare(){ echo -n " NITROX: "; read nitrox EQU=`echo "scale=2; 100-(((1-($nitrox/100))/0.79)*100)" | bc` echo " ${EQU}% less nitrogen" } po2(){ echo -n " Depth: "; read depth echo -n " NITROX: "; read nitrox PO2=`echo "scale=2; (($depth+10)/10)*($nitrox/100)" | bc` echo " PO2 at $depth MSW for NITROX $nitrox: $PO2 ATM" } cns(){ echo -n " PO2 [1.4, 1.5, 1.6]: "; read po2 echo -n " Duration: "; read duration if [ "$po2" == "1.4" ]; then CNS=`echo "scale=2; ($duration/150)*100" | bc` elif [ "$po2" == "1.5" ]; then CNS=`echo "scale=2; ($duration/120)*100" | bc` elif [ "$po2" == "1.6" ]; then CNS=`echo "scale=2; ($duration/45)*100" | bc` else echo " Choose between 1.4, 1.5 and 1.6 PO2" exit 1 fi echo " CNS for $duration minutes and $po2 PO2: ${CNS}%" } absolute(){ echo -n " Depth: "; read depth ABS=`echo "scale=2; (($depth/10)+1)" | bc` echo " Absolute pressure at depth of $depth MSW: $ABS ATM" } echo " 1 - Maximum Operational Depth (MOD)" echo " 2 - Operational Depth (OD)" echo " 3 - Best mix" echo " 4 - Equivelant Air Depth (EAD)" echo " 5 - Nitrogen percentage compared to Air" echo " 6 - Oxygen partial pressure (PO2)" echo " 7 - Central Nervous Systems Toxicity (CNS)" echo " 8 - Absolute pressure" echo echo -n " Function: "; read option disclaimer case "$option" in 1) mod ;; 2) od ;; 3) bestmix ;; 4) ead ;; 5) compare ;; 6) po2 ;; 7) cns ;; 8) absolute ;; *) echo " Please choose a valid option from the menu" exit 1 esac
Altitude diving depth and NITROX calculations
For several reasons I’ve found myself diving (with SCUBA) in inland lakes on altitude. Due to the lower atmospheric pressure, altitude diving requires different depth calculations. There are diving tables and computer software that help divers to plan a safe dive. Although, I’ve though of making my “quick and dirty” script for calculating the theoretical ocean depth of an altitude dive, the depth of the safety stop at altitude as well as the best NITROX mix at the given altitude for PO2 of 1.2, 1.4 and 1.6.
The scripts accepts only two parameters: the altitude and the depth. For instance, for a dive at 1350m altitude and 30m depth:
./calcDepth.sh 1350 30 ======================================================= Every individual diver is responsible for planning and conducting dives using SCUBA equipment up to the trained and certified qualification he or she holds. The creator of this program does not have any responsibility for symptoms of Decompressions Sickness when the suggested values of this program are used for conducting a dive. ======================================================== Altitude: 1350 m Depth: 30 mfw Pressure: .86 atm TOD: 33.65900 msw Safety Stop: 4.45 mfw Best NITROX mix with 1.2 PO2: 27.00 Best NITROX mix with 1.4 PO2: 32.00 Best NITROX mix with 1.6 PO2: 36.00
########################################################################### # Copyright (C) 2011 Panagiotis Kritikakos <panoskrt@gmail.com> # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################ #!/bin/bash MSW=10.0584 MFW=10.3632 SSDSW=5 ALT=$1 Da=$2 disclaimer() { echo " ======================================================= Every individual diver is responsible for planning and conducting dives using SCUBA equipment up to the trained and certified qualification he or she holds. The creator of this program does not have any responsibility for symptoms of Decompressions Sickness when the suggested values of this program are used for conducting a dive. ======================================================== " } if [ -z $ALT ] || [ -z $Da ]; then echo " Specify altitude and depth: ./calcDepth.sh 1350 24" exit 1 else clear Pa=`echo "100-(0.01*$ALT)" | bc` TOD=`echo "scale=5; ($Da*(1/$Pa)*($MSW/$MFW))*100" | bc` SSDA=`echo "scale=2; ($SSDSW*($Pa/1)*($MFW/$MSW))/100" | bc` PAatm=`echo "scale=2; $Pa/100" | bc` N1=`echo "scale=2; 100*(1.2/(($TOD/10)+1))" | bc` N2=`echo "scale=2; 100*(1.4/(($TOD/10)+1))" | bc` N3=`echo "scale=2; 100*(1.6/(($TOD/10)+1))" | bc` echo disclaimer echo printf "Altitude: \t$ALT m\n" printf "Depth: \t\t$Da mfw\n" printf "Pressure: \t$PAatm atm\n" printf "TOD: \t\t$TOD msw\n" printf "Safety Stop: \t$SSDA mfw\n\n" printf "Best NITROX mix with 1.2 PO2: $N1\n" printf "Best NITROX mix with 1.4 PO2: $N2\n" printf "Best NITROX mix with 1.6 PO2: $N3\n\n" exit 0 fi
Simple and very basic PBS/Torque emulator
PBS (Portable Batch System) is one of the common batch systems used across clusters. Unfortunately, proprietary piece of software. There used to be an open source version, OpenPBS which has been forked to Torque. Torque can be installed and configured to perform the basic operations within 15-20 minutes. Although, for evaluation purposes, I have wrote a *very simple* emulator for PBS/Torque. All it provides is three scripts:
– qsub -> submitting a job
– qstat -> displaying job list
– qdel -> removing job(s)
A virtual job can be submitted, without need of proper PBS or Torque-like submission script and other parameters. The parameters each script is accepting are:
– qsub – single virtual job: qsub test
– qstat – either username to list jobs of a user or none to list all jobs: qstat foobar
– qdel – single or list of job IDs to remove: qdel 1234 5678
Download: pbs-emu-0.1.tar.gz
Speedup and efficiency shell calculator
The following script can be used to calculate the speedup and efficiency of a parallel code when compared to its serial version. Pretty much straight forward process. This script can be used either individually or as part of another script to automate the process of generating the required results. It accepts three arguments: 1) serial execution time 2) parallel execution time 3) number of processors.
./SEcalc.sh <serial> <parallel> <procs>
Script:
############################################################################ # Copyright (C) 2011 Panagiotis Kritikakos <panoskrt@gmail.com> # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################ #!/bin/bash if [ "$#" -eq "3" ]; then runtime1proc=$1 runtimeNproc=$2 totalprocs=$3 speedup=`echo "${runtime1proc}/${runtimeNproc}" | bc -l`; efficiency=`echo "${speedup}/${totalprocs}" | bc -l`; printf "\n Total processors: ${totalprocs}\n\n"; printf " Runtime for serial code: ${runtime1proc}\n Runtime for parallel code: \ ${runtimeNproc}\n\n"; printf " Speedup: ${speedup}\n Efficiency: ${efficiency}\n\n"; else printf "\n Usage: SEcalc.sh \n\n"; printf " SEcalc.sh 0.350 0.494 2\n\n"; fi
OpenNebula DHCP leases – automatic lease discovery
OpenNebula uses a network template file that lists all the available IPs within a specific network that can be given to the Virtual Machines on an OpenNebula deployment. The template can define more details such as gateway, resolves, network class and so on. In our case, we just need a list of available leases for the VMs to pick up. The following script automates the process of getting listed all the available IPs within the network range of the bridged interface of the OpenNebula host machine, starting from checking the first IP after that of the bridged interface.
############################################################################ # Copyright (C) 2011 Panagiotis Kritikakos <pkritika@epcc.ed.ac.uk> # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################ #!/bin/bash if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then echo echo " This script will generate the appropriate leases for the Open Nebula Virtual Machines." echo " It will generate leases that for unused IPs that map to the bridged interface." echo echo " The default bridge interface is br0. If you want to change this, pass another interface as an argument." echo exit fi if [ "$1" == "" ]; then BRIDGE=br0 else BRIDGE=$1 fi IPADDR=`ifconfig $BRIDGE | grep "inet addr" | awk {'print $2'} | sed s/addr:*//g` BCAST=`ifconfig $BRIDGE | grep "inet addr" | awk {'print $3'} | sed s/Bcast:*//g` MASK=`ifconfig $BRIDGE | grep "inet addr" | awk {'print $4'} | sed s/Mask:*//g` if [ -e /etc/debian_version ]; then NETWORK=`ipcalc -n $IPADDR $MASK | grep Network | awk {'print $2'} | sed 's/\./ /g' \ | awk {'print $1"."$2"."$3'}` else NETWORK=`ipcalc -n $IPADDR $MASK | sed s/NETWORK=*//g | sed 's/\./ /g' | \ awk {'print $1"."$2"."$3'}` fi IPOCT=`ifconfig $BRIDGE | grep "inet addr" | awk {'print $2'} | sed s/addr:*//g | \ sed 's/\./ /g' | awk {'print $4'}` BCASTOCT=`ifconfig $BRIDGE | grep "inet addr" | awk {'print $3'} | sed s/Bcast:*//g | \ sed 's/\./ /g' | awk {'print $4'}` hostMin=$(($IPOCT + 1)) hostMax=$(($BCASTOCT - 2)) totalIP=$(($hostMax - $hostMin)) echo echo " $(($totalIP + 1)) IPs will be checked for availability. That might take some time..." iter=1 ONNET_FILE=hpce2_network.net printf 'NAME = "HPCE2"\n' > $ONNET_FILE printf 'TYPE = FIXED\n\n' >> $ONNET_FILE printf "BRIDGE = ${BRIDGE}\n" >> $ONNET_FILE echo for LEASE in `seq $hostMin $hostMax` do echo -n $iter " " ping -c 1 ${NETWORK}.$LEASE -W 1 > /dev/null; if [ $? -ne 0 ]; then printf 'LEASES = [ IP=''"'$NETWORK.$LEASE'"''] \n' >> $ONNET_FILE fi let iter++ done echo echo
Compiling SPEC Benchmarks tools on ARM
Some of the SPEC benchmarks come for a variety of architectures but not for ARM, which is not surprising anyway. The easiest way to execute the benchmarks is by using the provided scripts, which is pretty much straight forward operation. The benchmarks come with pre-compiled tools and libraries that are needed by the benchmarks. Among them is Perl, which will fail to compile on ARM systems because of some invalid object definitions in its makefile. These definitions get in the makefile by the Configure script which is called before calling make. Instead of messing around with Configure, I added a couple of lines in the buildtools file, which is responsible for building the SPEC tools on a new architecture or after having modified the host system, in order to remove the unnecessary lines from the corresponding makefiles.
The buildtools script can be found under tools/src/ in the SPEC benchmarks directoy. What is needed is to go in the Perl building section, line 103, and replace the fist part of the building phase with the following oneliner:
(cd $PERLSRC; LD_LIBRARY_PATH=`pwd`; export LD_LIBRARY_PATH; ./Configure -dOes $PERLFLAGS -Ddosuid=undef -Dprefix=$INSTALLDIR -Dd_bincompat3=undef; cat makefile | grep -v built-in | grep -v "command line" > makefile.new; cp makefile.new makefile; cat x2p/makefile | grep -v built-in | grep -v "command line" > x2p/makefile.new; cp x2p/makefile.new x2p/makefile; make; ./perl installperl ) || die "Can't build perl"
You must be logged in to post a comment.