-- Nécessite le programme links
1 #!/bin/bash
2
3 links -dump http://www.whatismyip.com/automation/n09230945.asp | sed -e 's/ //g'
Everytime my computer starts, I have to select "Sync to my second screen" in nvidia-settings. Otherwise it sync to the first display. This command does the job in a terminal and can be automated.
1 nvidia-settings --assign XVideoSyncToDisplay=2
Juste un script qui se charge de faire un screenshot, le place dans un répertoire donné, et affiche une miniature de ce qui à été capturé. La capture se fait en utilisant scrot (par défaut) ou import (si scrot n'est pas présent) Testé on Linux and Solaris
1 #!/usr/bin/env bash
2 #
3 #printscreen.sh written by : nali <phobos@goupilfr.org>
4 # enhanced by : slubman <slubman@ifrance.com>
5 # this script is free software according to the
6 # GNU General Public License (see http://www.gnu.org/licenses/gpl.html)
7 #
8 #
9 # This script make a screenshot and save it to a default location
10 # You can customize some component by editing variables:
11 # * REP_SAVE
12 # * IMG_PREF
13 # * IMG_UNIQ
14 # * IMG_VIEW
15 # * IMG_SIZE
16 #
17 # The script first try to use the scrot program, if not found it default on import
18 #
19 ###########################################################
20
21
22 # Modify the following variables to fetch what you want:
23 #repertoire des sauvegardes
24 REP_SAVE=~/Documents/Captures
25
26 # Prefixe du nom des images
27 IMG_PREF=capture
28
29 # Estampille (unique) des images
30 IMG_UNIQ=`date +%Y-%m-%d-%H%M%S`
31
32 # View Image (0=no , 1=yes : this feature depend on the display program) ?
33 IMG_VIEW=1
34
35 # Display image resize
36 IMG_SIZE="840x625"
37
38
39
40 ###########################################################
41 # You really don't need to edit anything bellow this line #
42 ###########################################################
43
44 #Delai en sec. avant la capture . Peut etre interessant a mettre par exemple a
45 #5 ou 10 secondes pour capturer des screen savers.
46
47 [ "$1" ] && DELAY=$1
48
49 ###########################################################
50
51 #repertoire des captures non datees
52 REP_TEMP=$REP_SAVE/tmp
53
54 #creation du repertoire des sauvegardes si il n existe pas
55 [ ! -d $REP_SAVE ] && mkdir $REP_SAVE
56
57 #creation du repertoire des sauvegardes avant "datage", si il n existe pas
58 [ ! -d $REP_TEMP ] && mkdir $REP_TEMP
59
60 ###########################################################
61
62 # Verification de l'exitence de import
63 CAPTURE_CMDS=(scrot import)
64 for CAPTURE_CMD in ${CAPTURE_CMDS[@]};
65 do
66 which $CAPTURE_CMD
67 if [ $? -eq 0 ]; then
68 echo "Using $CAPTURE_CMD for the capture !!"
69 break
70 fi
71 done
72
73 # Verification de l'exitence de display
74 if [ IMG_VIEW == "1" -a ! $(which display) ]; then
75 echo "display program not found, please install ImageMagick (http://www.imagemagick.org)"
76 exit
77 fi
78
79 #nom de l'image avant datage
80 NOM_TEMP=$IMG_PREF.png
81
82 #nettoyage du temp
83 cd $REP_TEMP
84 rm -f $NOM_TEMP
85
86 #capture de l'image
87 [ $DELAY ] && sleep $DELAY
88 case $CAPTURE_CMD in
89 scrot)
90 scrot -m $NOM_TEMP
91 ;;
92 import)
93 import -window root $NOM_TEMP
94 ;;
95 *)
96 echo "Unknown capture command"
97 exit
98 ;;
99 esac
100
101
102 #ajout de la date et heure au nom de la capture
103 #c'est pas beau mais ca marche :)
104 SEPARATEUR=-
105 NOM_DATE=`basename $NOM_TEMP .png`$SEPARATEUR$IMG_UNIQ.png
106
107 cp $NOM_TEMP $NOM_DATE
108
109 mv $NOM_DATE $REP_SAVE
110
111 #affichage en mode reduit
112 [ $IMG_VIEW == "1" ] && display -resize $IMG_SIZE "$REP_SAVE/$NOM_DATE" &
113
114 #nettoyage du temp , pour laisser propre en partant ...
115 cd $REP_TEMP
116 rm -f $NOM_TEMP
This program allow to update a dns from a dynamic ip. It use nsupdate to add and delete any record from a dns zone. It update it securly thanks a key you set before. Currently it support only anames.
1 #!/usr/local/bin/python2.4
2 #
3 # Copyright (c) 2007 Benoit Chesneau <benoit@bchesneau.info>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #
17 # Description :
18 # This program allow to update a dns from a dynamic ip. It use nsupdate to add
19 # and delete any record from a dns zone. It update it securly thanks a key you
20 # set before. Currently it support only anames.
21 #
22 # It require to create a configuration file /etc/ddns.conf or ~/.ddns.conf :
23 # add a zone like this :
24 # [domain1]
25 # key=<path to your private key>
26 # server = <name of dns>
27 # zone = <zone name>
28 # anames = <anames you want to add/update>
29 #
30 # Add as any zone you want by creating section [domainXX] in your
31 # configuration file.
32 #
33 #
34 # For more information on setting your dns ypu can go here :
35 # * nsupdate: Painless Dynamic DNS: http://linux.yyz.us/nsupdate/
36 # * A DDNS Server Using BIND and Nsupdate : http://www.oceanwave.com/technical-resources/unix-admin/nsupdate.html
37 # * DynDNS et Subzone ARPA : http://wiki.gcu.info/doku.php?id=unix:dyndns&s=bind
38
39
40 import re
41 import urllib
42 import ConfigParser
43 import os
44 import time
45
46 checkip_urls = (
47 (r'Current IP Address:\s(?P<ip>[^<]*)', 'http://checkip.dyndns.org/'),
48 (r'Current Address:\s(?P<ip>.*)$', 'http://ipdetect.dnspark.com/'),
49 )
50
51 rIP=re.compile("(\d{1,3}(\.\d{1,3}){3})(?!/\d+)")
52 cmd = '/usr/sbin/nsupdate'
53
54 def get_ip():
55 """
56 For now we get dynamic ip only from web.
57 TODO: add detection from interface and router
58 """
59 f = None;
60 ip=None
61 for u in checkip_urls:
62 pat = re.compile(u[0]);
63 try:
64 f = urllib.urlopen(u[1])
65 except:
66 continue
67
68 if f:
69 for line in f.readlines():
70 match = pat.search(line)
71 if match is not None:
72 ip=match.group('ip')
73 if rIP.search(ip):
74 return ip
75
76 return ip
77
78 def get_conffile():
79 conffiles = ("~/.ddns.conf", "/etc/ddns.conf",)
80 for c in conffiles:
81 path = os.path.expanduser(c)
82 if os.path.exists(path):
83 return path
84 return None
85
86 def get_conf():
87 domains = []
88 config = ConfigParser.ConfigParser()
89 config.read(get_conffile())
90 for section in config.sections():
91 if section.startswith('domain'):
92 anames = config.get(section, 'anames').split(',')
93 domains.append({
94 'key_path': config.get(section, 'key'),
95 'anames': [aname.strip() for aname in anames],
96 'server': config.get(section, 'server').strip(),
97 'zone': config.get(section, 'zone').strip(),
98 })
99 return domains
100
101 def nsupdate(domain, ip):
102 tmp_path = '/var/tmp/.ddns_%s.txt' % domain['server']
103 aname_str=""
104 for aname in domain['anames']:
105 if aname_str != "": aname_str="\n"
106 aname_str+="""update delete %(aname)s A
107 update add %(aname)s 60 A %(ip)s
108 show
109 send""" % {
110 'aname': aname,
111 'ip': ip,
112 }
113 tmp_str = """server %(server)s
114 zone %(zone)s
115 %(aname_str)s
116 """ % {
117 'server': domain['server'],
118 'zone': domain['zone'],
119 'aname_str': aname_str,
120
121
122 }
123
124 fdomain = open(tmp_path, 'w+')
125 fdomain.write(tmp_str)
126 fdomain.close()
127 cmd_str = "%s -k %s -v %s" % (cmd,domain['key_path'],tmp_path)
128 os.system(cmd_str)
129
130 def update_dns():
131 ip_path = "/var/tmp/.ddns_ip"
132 while True:
133 ip=get_ip()
134 if os.path.exists(ip_path):
135 f = open(ip_path, 'r')
136 old_ip = f.readline()
137 f.close()
138 else:
139 old_ip = ""
140
141 if ip != old_ip:
142 f=open(ip_path, 'w')
143 f.write(ip)
144 f.close()
145 domains = get_conf()
146 if not domains:
147 print 'no domain configured yet.'
148 os._exit(1)
149 for domain in domains:
150 nsupdate(domain, ip)
151
152 time.sleep(60)
153
154
155 ip=get_ip()
156 domains = get_conf()
157 if not domains:
158 print 'no domain configured yet.'
159 os._exit(1)
160
161 try:
162 if os.fork() > 0: os._exit(0) # exit father...
163 except OSError, error:
164 print 'fork #1 failed: %d (%s)' % (error.errno, error.strerror)
165 os._exit(1)
166
167 os.chdir('/')
168 os.setsid()
169 os.umask(0)
170
171 try:
172 pid = os.fork()
173 if pid > 0:
174 f = open('/tmp/ddns.pid', 'w')
175 f.write("%i" % pid)
176 f.close()
177 os._exit(0)
178 except OSError, error:
179 print 'fork #2 failed: %d (%s)' % (error.errno, error.strerror)
180 os._exit(1)
181
182 update_dns()
Resize a lot of images with shell and imagemagick
1 for i in *.jpg
2 do convert $i -scale 1024x760 resized-$i;
3 done
Script to upload images to imageshack from console. Require bash and curl.
1 #!/bin/bash
2 #
3 # imageshack_upload.sh
4 #
5 # Copyright (c) 2007 by enki <enki@crocobox.org>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 # USA.
21 #
22 # Changelog :
23 # * 2006/10/22 - Updated to support files with space .
24 # Changes proposed by slubman(http://www.slubman.net)
25 # * 2006/10/22 - First version
26
27 myver='0.2'
28 CURL=$(which curl)
29
30
31
32 TMPFILE=$(mktemp /tmp/imageshack.XXXXXXXXXX) || exit 1
33
34 cleanup() {
35 rm -rf $TMPFILE
36 [ "$1" ] && exit $1
37 }
38
39 usage() {
40 echo "imageshack_upload $myver"
41 echo "usage: $0 <root>"
42 echo
43 echo "This script allow you to send image to htpp://www.imageshack.us"
44 echo "in command line"
45 echo
46 echo "example: imageshack_upload.sh `pwd`/myimage.png"
47 echo
48 }
49
50 if [ $# -lt 1 ]; then
51 usage
52 rm -rf $TMPFILE
53 exit 1
54 fi
55
56 if [ "$1" = "-h" -o "$1" = "--help" ]; then
57 usage
58 rm -rf $TMPFILE
59 exit 0
60 fi
61
62
63 img="$1"
64
65 if ! [ -f "$img" ]; then
66 echo "Error: file don't exist"
67 exit 1
68 fi
69
70 $CURL -H Expect: -F fileupload="@${img}" -F xml=yes http://www.imageshack.us/index.php > $TMPFILE
71
72 echo "Url of image on imageshack:"
73 echo $(cat $TMPFILE | grep -E "<image_link>(.*)</image_link>" | sed 's|<image_link>\(.*\)</image_link>|\1|')
74
75 cleanup
Pages : 1