#!/bin/bash function usage { echo "Usage:" echo "$0 --all|-a website" echo "$0 --sync|-s website" echo "$0 --deploy|-d website" } case $2 in 'website') project_repository="http://repository.ctld/website/trunk/" dir="/home/hio/repository/website.com/" prod_dir="/home/www/website.com/" exclude_list=".svn frontend_test.php frontend_dev.php auth.php backend_dev.php" ;; *) usage exit 1 esac if [[ $1 == "--all" || $1 == "-a" ]]; then $0 --sync $2 $0 --deploy $2 fi if [[ $1 == "--sync" || $1 == "-s" ]]; then if [ ! -d "$project_repository" ]; then svn co $project_repository $dir else svn up $dir fi fi for e in $exclude_list do excludes="$excludes --exclude '$e'" done if [[ $1 == "--deploy" || $1 == "-d" ]]; then rsync="sudo rsync -rha --stats $excludes $dir $prod_dir" echo $rsync eval $rsync sudo chown www-data:www-data -R $prod_dir fi
Tag Archives: script
mass_update.sh
#!/bin/bash hosts="hio@host1.com hio@host2.com hio@host3.com hio@host4.com hio@host5.com" cmd="echo 'updating ...';sudo aptitude update >> /dev/null;sudo aptitude safe-upgrade -y;echo 'done'" for i in $hosts do echo "###### connecting to $i ..." ssh -t $i $cmd echo "" done
playlist.py
#!/usr/bin/python # -*- coding: utf-8 -*- import os import mimetypes import string import sys import shutil import getopt import re class main: def usage(self): print('%s %s dir te explore'%('-i', '--indir')) print('%s %s playlist output'%('-p', '--playlist')) print('exemple: %s %s %s'%(__file__, '--indir=/var/www/mp3', '-p ./blu.xml')) def __init__(self, argv): self.indir = 0 self.playlist = 'playlist.xml' try: opts, args = getopt.getopt(argv, "i:p", ["indir=", "playlist="]) except getopt.GetoptError: self.usage() sys.exit(2) for opt, arg in opts: if opt in ('-i', '--indir'): if(os.path.exists(arg) == 0): sys.exit(1) print('walk %s'%(arg)) self.indir = arg elif opt in ('-p', '--playlist'): print('playlist %s'%(arg)) self.playlist = arg if self.indir != 0: self.run() else: self.usage() def strReplace(self, str, array): for search, replace in array: str = str.replace(search, replace) return str def _human_key(self, key): parts = re.split('(\d*\.\d+|\d+)', key) return tuple((e.swapcase() if i % 2 == 0 else float(e)) for i, e in enumerate(parts)) def run(self): print 'run' xml = '<?xml version="1.0" encoding="UTF-8"?>\n' xml += '<playlist version="1" xmlns="http://xspf.org/ns/0/">\n' xml += '<title>'+os.path.split(self.playlist)[1].replace('_', ' ').replace('.xml', '')+'</title>\n' xml += '<creator>Bayard</creator>\n' xml += '<link></link>\n' xml += '<info></info>\n' xml += '<image></image>\n' xml += '<trackList>\n' for dirpath, dirnames, filenames in os.walk(self.indir): c = os.path.split(dirpath)[1] filenames.sort(key=self._human_key) for filename in filenames: print dirpath+'/'+filename newfilename = self.strReplace(filename, [(' ', '_'), ('–', '-')]); fo_path = os.path.join(dirpath, filename) fn_path = os.path.join(dirpath, newfilename) f_mime = mimetypes.guess_type(fo_path) if(os.path.exists(fn_path) == 0): print('%s move to %s'%(fo_path, fn_path)) shutil.move(fo_path, fn_path) if f_mime[0] == 'audio/mpeg': xml += ' <track>\n' xml += ' <title>'+newfilename.replace('_', ' ').replace('.mp3', '')+'</title>\n'; xml += ' <location>http://bayardmusique.bayardcdn.com/'+c+'/'+filename+'</location>\n'; xml += ' </track>\n' xml += '</trackList>\n' xml += '</playlist>' self.write(xml) def write(self, xml): print('write %s'%(self.playlist)) f = open(self.playlist, 'w') f.write(xml) f.close() if __name__ == "__main__": main(sys.argv[1:])
install_symfony2.sh
#!/bin/bash function usage { echo "Usage:" echo "$0 /home/www/mySf2Project" } if [[ $1 == "" ]]; then usage exit 1 fi cd $1 if [ -d "app/" ]; then echo "already installed, do a <git pull> if you want an update :)" exit 1 fi git clone git://github.com/symfony/symfony-standard.git mv symfony-standard/* . mv symfony-standard/.git* . rmdir symfony-standard bash bin/vendors.sh && php bin/build_bootstrap.php echo "chmod -R 777 app/cache/ app/logs/" chmod -R 777 app/cache/ app/logs/ exit 0
import.sh
#!/bin/bash date_format="+%d/%m/%Y %H:%M:%S" dir="/home/smile" mysql_client="mysql -u import -pP4S5W0RD" echo `date "$date_format"`" start" cd $dir if [ ! -d "tmp" ];then mkdir tmp fi if [ ! -d "bak" ];then mkdir bak fi for i in `ls *.sql.gz` do f=`echo $i|cut -d'.' -f1-2` db_name=`echo $i|cut -d'-' -f1` echo `date "$date_format"`" gzip -d $i -c > tmp/$f" gzip -d $i -c > tmp/$f echo `date "$date_format"`" mysql -u import -p***** $db_name < tmp/$f" $mysql_client <<EOF DROP DATABASE $db_name ; CREATE DATABASE $db_name ; EOF $mysql_client $db_name < tmp/$f mv $i bak/$i rm tmp/$f done echo `date "$date_format"`" end"
10/04/2011 08:00:01 start 10/04/2011 08:00:01 gzip -d bayardsso_prod-201104100542.sql.gz -c > tmp/bayardsso_prod-201104100542.sql 10/04/2011 08:00:02 mysql -u import -p***** bayardsso_prod < tmp/bayardsso_prod-201104100542.sql 10/04/2011 08:01:18 gzip -d notretemps-201104090006.sql.gz -c > tmp/notretemps-201104090006.sql 10/04/2011 08:01:45 mysql -u import -p***** notretemps < tmp/notretemps-201104090006.sql 10/04/2011 08:33:20 gzip -d notretemps_outils-201104090006.sql.gz -c > tmp/notretemps_outils-201104090006.sql 10/04/2011 08:33:20 mysql -u import -p***** notretemps_outils < tmp/notretemps_outils-201104090006.sql 10/04/2011 08:33:20 gzip -d phosphore-201104100040.sql.gz -c > tmp/phosphore-201104100040.sql 10/04/2011 08:34:20 mysql -u import -p***** phosphore < tmp/phosphore-201104100040.sql 10/04/2011 10:23:21 end
arbo.sh
#!/bin/bash dir="/home/www/bayardcdn.com/bj.emailing" month[1]=`date +%Y/%m` month[2]=`date +%Y/%m --date "+1 month"` month[3]=`date +%Y/%m --date "+2 month"` month[4]=`date +%Y/%m --date "+3 month"` m_nb=`seq 1 4` chmod u+w,g+w,o-w -R $dir for i in $m_nb do if [ ! -d "$dir/${month[$i]}" ]; then echo "mkdir -p $dir/${month[$i]}" mkdir -p "$dir/${month[$i]}" fi done chmod u-w,g-w,o-w -R $dir for i in $m_nb do if [ -d "$dir/${month[$i]}" ]; then echo "chmod u+w,g+w -R $dir/${month[$i]}" chmod u+w,g+w -R $dir/${month[$i]} fi done
PYTHON Script, Couper des mp3 recursivement
Script qui sert a répliquer l’arborescence d’un répertoire de mp3 dans un repertoire de sortie en les coupant pour faire des extrait musicaux, c’est pas beau tout ça ?!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #!/usr/bin/python import os import mimetypes import string import sys import shutil input = '/media/disk/originaux/' output = '/media/disk/extraits/' def grey(string): return '\x1b\x5b1;30;40m%s\x1b\x5b0;37;40m'%(string) def red(string): return '\x1b\x5b1;31;40m%s\x1b\x5b0;37;40m'%(string) def green(string): return '\x1b\x5b1;32;40m%s\x1b\x5b0;37;40m'%(string) def yellow(string): return '\x1b\x5b1;33;40m%s\x1b\x5b0;37;40m'%(string) def blue(string): return '\x1b\x5b1;34;40m%s\x1b\x5b0;37;40m'%(string) def orange(string): return '\x1b\x5b1;40;40m%s\x1b\x5b0;37;40m'%(string) if(os.path.exists(output) == 0): print("mkdir %s"%(output)) os.mkdir(output) #On preparre le repertoire de sortie en replicant l'arborescence du repertoire d'entre for dirpath, dirnames, filenames in os.walk(input): tmp = dirpath.replace(input, output) if(os.path.exists(tmp) == 0): print('mkdir %s'%(tmp)) os.mkdir(tmp) mp3_count = 0 xml_count = 0 mp3_cut = 0 #On fait cqu'on a faire, forcement a un moment faut y aller et on va se prendre un cafe for dirpath, dirnames, filenames in os.walk(input): for filename in filenames: f_mime = mimetypes.guess_type(filename) if f_mime[0] == 'audio/mpeg': mp3_count += 1 mp3_in = os.path.join(dirpath, filename) mp3_out = os.path.join(dirpath.replace(input, output), filename) cut_line = 'cutmp3 -i "%s" -a 0:30 -b 1:00 -O "%s"'%(mp3_in, mp3_out) if(os.path.exists(mp3_out) == 0): mp3_cut += 1 print('#%s %s (%s)\n cut to \n %s'%(grey(mp3_cut) ,yellow(mp3_in), blue(f_mime[0]) , green(mp3_out))) a = os.popen('%s'%(cut_line)).readlines() for p in a: if p != '\n': if 'ERROR' in p: print(' %s'%(red(p.strip()))) elif 'WARNING' in p: print(' %s'%(red(p.strip()))) else: print(' %s'%(green(p.strip()))) elif f_mime[0] == 'application/xml': xml_count += 1 xml_in = os.path.join(dirpath, filename) xml_out = os.path.join(dirpath.replace(input, output), filename) if(os.path.exists(xml_out) == 0): print(' %s (%s) copy to %s'%(blue(xml_in), blue(f_mime[0]) , blue(xml_out))) shutil.copyfile(xml_in, xml_out) print print(' mp3 count: %s, xml count: %s, mp3 cutted: %s'%(green(mp3_count), green(xml_count), green(mp3_cut))) print |
PYTHON Script, verifier la syntaxe d’un projet php
python php_syntax.py (-e pour voir seulement les fichiers contenant une erreur)
import os import mimetypes import string import sys def red(string): return '\x1b\x5b1;31;40m%s\x1b\x5b0;37;40m'%(string) def green(string): return '\x1b\x5b1;32;40m%s\x1b\x5b0;37;40m'%(string) def count(list): line_count = 0 for line in list: line_count += 1 return line_count mimeArray = ['application/x-httpd-php'] errors_count = 0 files_count = 0 lines_count = 0 bytes_count = 0 if '-e' in sys.argv: showonlyerror = 1 else: showonlyerror = 0 for path, dirs, files in os.walk('.'): for file in files: f_mime = mimetypes.guess_type(file) if f_mime[0] in mimeArray: f_path = os.path.join(path, file) a = os.popen('php -l %s'%(f_path)).readlines() b = open(f_path) counta = count(a) sizea = os.path.getsize(f_path) line_count = count(b) files_count += 1 bytes_count += sizea lines_count += line_count if counta > 1: errors_count += 1 print('%s'%(red(f_path))) print(' %s, %s line(s), %s byte(s)'%(f_mime[0], line_count, sizea)) for p in a: if p != '\n': print(' %s'%(p.strip())) else: if showonlyerror == 0: print('%s'%(green(f_path))) print(' %s, %s line(s), %s byte(s)'%(f_mime[0], line_count, sizea)) for p in a: print(' %s'%(p.strip())) print if errors_count > 0: print(' file(s): %i, lines: %i, bytes: %i, error: %s'%(files_count, lines_count, bytes_count, red(errors_count))) else: print(' file(s): %i, lines: %i, bytes: %i, error: %s'%(files_count, lines_count, bytes_count, green(errors_count)))
