Cette page est en cours d'edition.
Information sur la page
Cette page contient uniquement les codes sources avec les explications de : http://glx-dock.org/ww_page.php?p=Doncky%20setups&lang=fr.
divers scripts ont été crées par taiebot65 et ours_en_pluche
Généralités #!/usr/bin/perl
#shebang
#permet d'avoir un code source pas trop pourri :)
use strict;
use warnings;
Code Source
Afficher sa release
#!/usr/bin/perl
use strict;
use warnings;
#renvoi Description: Ubuntu 12.04.1 LTS
my $a = `lsb_release -d`;
#renvoi Codename: precise
my $b = `lsb_release -c`;
# on retire le caractere de fin de ligne
$a =~ s/\n//g;
# on retire les tabulations
$a =~ s/\t//g;
#idem que precedemment
$b =~ s/\n//g;
$b =~ s/\t//g;
#on retire Description: et tout ce qu'il y a avant
$a =~ s/.*Description://g;
#on retire Codename: et tout ce qu'il y a avant
$b =~ s/.*Codename://g;
#on affiche le resultat
print $a." ( ".$b." )\n";
Afficher le nom du compte connecté #!/usr/bin/perl
use strict;
use warnings;
#affiche le resultat de la variable d environnement
print $ENV{USER}."\n";
Afficher le Load Average #!/usr/bin/perl
use strict;
use warnings;
my $loadavg = `uptime`;
$loadavg =~ s/.*load\saverage:\s(.*)\n$/$1/;
print $loadavg."\n";
Uptime #!/usr/bin/perl
use strict;
use warnings;
my $uptime = `uptime`;
$uptime =~ s/.*up\s(.*),(\s+)(\d+)\susers,.*\n$/$1/;
print $uptime."\n";
Nombre de processus perl programme.pl total|run|sleep|stop|zombie
#!/usr/bin/perl
use strict;
use warnings;
sub help {
print "programme <option>\n\t<option> = total|run|sleep|stop|zombie\n";
exit;
}
if ( defined($ARGV[0]) ) {
my $process = `top -n 1 | head -n 2 | tail -n 1`;
if ( $ARGV[0] eq "total" ) {
$process =~ s/.*Tasks:(.*)total.*\n$/$1/;
$process =~ s/(\t)|(\s)//g;
print $process."\n";
} elsif ( $ARGV[0] eq "run" ) {
$process =~ s/.*total,(.*)running.*\n$/$1/;
$process =~ s/(\t)|(\s)//g;
print $process."\n";
} elsif ( $ARGV[0] eq "sleep" ) {
$process =~ s/.*running,(.*)sleeping.*\n$/$1/;
$process =~ s/(\t)|(\s)//g;
print $process."\n";
} elsif ( $ARGV[0] eq "stop" ) {
$process =~ s/.*sleeping,(.*)stopped.*\n$/$1/;
$process =~ s/(\t)|(\s)//g;
print $process."\n";
} elsif ( $ARGV[0] eq "zombie" ) {
$process =~ s/.*stopped,(.*)zombie.*\n$/$1/;
$process =~ s/(\t)|(\s)//g;
print $process."\n";
} else {
&help;
}
} else {
&help;
}
Afficher son IP addresse externe
version bash :
#!/bin/bash
# voir ip derriere routeur
wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1 > ip
cat ip
version perl :
#!/usr/bin/perl
use strict;
use warnings;
my $a = `dig +short myip.opendns.com \@resolver1.opendns.com`;
$a =~ s/\n//g;
print $a."\n";
Afficher son ip locale
#!/usr/bin/perl
use strict;
use warnings;
my $wifi = `ifconfig wlan0`;
my $ethernet = `ifconfig eth0`;
if ( $wifi =~ /.*inet\sadr.*/ ) {
$wifi = `ifconfig wlan0 | grep "inet adr"`;
$wifi =~ s/.*inet\sadr://g;
$wifi =~ s/Bcast:.*//g;
$wifi =~ s/\s//g;
print $wifi."\n";
} elsif ( $ethernet =~ /.*inet\sadr.*/ ) {
$ethernet = `ifconfig eth0 | grep "inet adr"`;
$ethernet =~ s/.*inet\sadr://g;
$ethernet =~ s/Bcast:.*//g;
$ethernet =~ s/\s//g;
print $ethernet."\n";
} else {
print "NA\n";
}
Afficher si l'on est connecté en wifi ou ethernet
#!/usr/bin/perl
use strict;
use warnings;
my $wifi = `ifconfig wlan0`;
my $ethernet = `ifconfig eth0`;
if ( $wifi =~ /.*inet\sadr.*/ ) {
print "Wifi\n";
} elsif ( $ethernet =~ /.*inet\sadr.*/ ) {
print "Ethernet\n";
} else {
print "NA\n";
}
Température
Cpu
#!/usr/bin/perl
use strict;
use warnings;
my $a = `acpi -t`;
$a =~ s/.*,//g;
$a =~ s/\n//g;
$a =~ s/degrees\sC//g;
$a =~ s/\s//g;
print $a."\n";
Gpu
Version Nvidia
#!/usr/bin/perl
use strict;
use warnings;
my $a = `nvidia-settings -q gpucoretemp | grep Attribute`;
$a =~ s/.*://g;
$a =~ s/\n//g;
$a =~ s/\s//g;
$a =~ s/\.//g;
print $a.".0\n";
Résolution d'écran
#!/usr/bin/perl
use strict;
use warnings;
my $a = `xrandr -q | grep Screen`;
$a =~ s/\n//g;
$a =~ s/.*current\s//g;
$a =~ s/,\smaximum.*//g;
print $a."\n";
Afficher la version du driver Nvidia propriétaire #!/usr/bin/perl
use strict;
use warnings;
my $a = `nvidia-smi -q | grep Driver | grep Version`;
$a =~ s/\n//g;
$a =~ s/.*://g;
$a =~ s/\s//g;
print $a."\n";
Obtenir une image satellite de son pays
perl <nom_du_programme.pl> <pays> <largeur> <hauteur>
( necessite d'avoir convert d'ImageMagick d'installé )
#!/usr/bin/perl
use strict;
use warnings;
use FindBin;
my $dir = $FindBin::Bin;
if ( !defined($ARGV[0]) or !defined($ARGV[1]) or !defined($ARGV[2]) ) {
print "perl imgsat.pl fr|en|de|es|pt|it|ca|usnw|uscw|ussw|usnc|uscc|ussc|usne|usce|usse largeur hauteur\n";
exit;
}
if ( ! -d $dir."/img/" ) { `mkdir $dir/img/`; }
if ( ! -d $dir."/img/sat/" ) { `mkdir $dir/img/sat/`; }
if ( ($ARGV[0] eq "fr") or ($ARGV[0] eq "en") or ($ARGV[0] eq "de") or ($ARGV[0] eq "es") or ($ARGV[0] eq "pt") or ($ARGV[0] eq "it") ) {
`cd $dir/img/sat/ && wget -m -nd http://oiswww.eumetsat.org/IPPS/html/latestImages/EUMETSAT_MSG_VIS006EColor-westernEurope.jpg`;
`cp $dir/img/sat/EUMETSAT_MSG_VIS006EColor-westernEurope.jpg $dir/img/sat/imagesattmp.jpg`;
} elsif ( ($ARGV[0] eq "usnw") or ($ARGV[0] eq "ussw") or ($ARGV[0] eq "usne") or ($ARGV[0] eq "uscw") or ($ARGV[0] eq "uscc") or ($ARGV[0] eq "usce") or ($ARGV[0] eq "usnc") or ($ARGV[0] eq "ussc") or ($ARGV[0] eq "usse") ) {
`cd $dir/img/sat/ && wget --no-check-certificate -m -nd https://www.nrlmry.navy.mil/focus_public/CONUS/focus_regions/Full/Overview/vis_ir_background/goes/CURRENT.jpg`;
`cp $dir/img/sat/CURRENT.jpg $dir/img/sat/imagesattmp.jpg`;
} elsif ( $ARGV[0] eq "ca" ) {
`cd $dir/img/sat/ && wget -m -nd http://www.meteo.gc.ca/data/satellite/goes_ecan_vvi_100.jpg`;
`cp $dir/img/sat/goes_ecan_vvi_100.jpg $dir/img/sat/imagesattmp.jpg`;
} else {
print "perl imgsat.pl fr|en|de|es|pt|it|ca|usnw|uscw|ussw|usnc|uscc|ussc|usne|usce|usse largeur hauteur\n";
exit;
}
my ($up,$down);
if ( $ARGV[0] eq "fr" ) {
$up = "617x432+260+100";
$down = "357x332-107-177";
} elsif ( $ARGV[0] eq "en" ) {
$up = "617x432+205+45";
$down = "357x332-107-177";
} elsif ( $ARGV[0] eq "de" ) {
$up = "617x432+342+55";
$down = "357x332-107-177";
} elsif ( $ARGV[0] eq "es" ) {
$up = "617x432+182+185";
$down = "357x332-107-177";
} elsif ( $ARGV[0] eq "pt" ) {
$up = "617x432+182+185";
$down = "357x332-107-177";
} elsif ( $ARGV[0] eq "it" ) {
$up = "617x432+367+160";
$down = "357x332-107-177";
} elsif ( $ARGV[0] eq "ca" ) {
$up = "1024x1024+409+214";
$down = "615x810-140-500";
} elsif ( $ARGV[0] eq "usnw" ) {
$up = "1300x800+210+88";
$down = "1090x712-746-499";
} elsif ( $ARGV[0] eq "uscw" ) {
$up = "1300x800+210+301";
$down = "1090x499-746-286";
} elsif ( $ARGV[0] eq "ussw" ) {
$up = "1300x800+210+514";
$down = "1090x286-746-73";
} elsif ( $ARGV[0] eq "usnc" ) {
$up = "1300x800+554+88";
$down = "746x712-402-499";
} elsif ( $ARGV[0] eq "uscc" ) {
$up = "1300x800+554+301";
$down = "746x499-402-286";
} elsif ( $ARGV[0] eq "ussc" ) {
$up = "1300x800+554+514";
$down = "746x286-402-73";
} elsif ( $ARGV[0] eq "usne" ) {
$up = "1300x800+898+88";
$down = "402x712-58-499";
} elsif ( $ARGV[0] eq "usce" ) {
$up = "1300x800+898+301";
$down = "402x499-58-286";
} elsif ( $ARGV[0] eq "usse" ) {
$up = "1300x800+898+514";
$down = "402x286-58-73";
}
`cd $dir/img/sat/ && convert imagesattmp.jpg -crop $up imagesattmp.jpg`;
`cd $dir/img/sat/ && convert imagesattmp.jpg -crop $down image.jpg`;
`cd $dir/img/sat/ && convert image.jpg -resize $ARGV[1]x$ARGV[2]\! image.jpg`;
`cd $dir/img/sat/ && rm -rf imagesattmp.jpg`;
Phases de la lune
Necessite Astro::MoonPhase disponible sur CPAN
#!/usr/bin/perl
use strict;
use warnings;
use Astro::MoonPhase;
use FindBin;
my $dir = $FindBin::Bin;
my (undef,$moonillu,undef,undef,undef,undef,undef) = phase(time);
$moonillu = int($moonillu*100);
$dir = $dir."/img/moon";
my $file = $moonillu.".png";
`rm -rf $dir/moon.png && cp -r $dir/$file $dir/moon.png`;
Afficher des VDM
#!/usr/bin/perl
use strict;
use warnings;
my $vdm_choisi;
my @vdm;
if (!defined($ARGV[0])) {
print "[Cairo-Dock][vdm applet] no option defined\nNeed lenght cut in option\n";
exit;
}
sub getvdm {
my $vdm_link = "http://www.viedemerde.fr/data/fr/fortunes";
my $dl = `curl -s --user-agent "Mozilla/5.0" $vdm_link`;
my $phrase = "";
foreach my $a (split(/\n/,$dl)) {
if ( $a =~ /^Aujourd.*VDM$/ ) {
$phrase = $phrase."\n".$a;
}
}
$phrase =~ s/^\n//g;
@vdm = split(/\n/,$phrase);
}
sub choosevdm {$vdm_choisi = $vdm[int(rand(@vdm))]; }
sub vdm_get {
&getvdm;
&choosevdm;
if ( $vdm_choisi eq "" ) { &choosevdm; }
my @vdm_choisi_split = split(/\s/,$vdm_choisi);
my $phrase_final = "";
my $tmp = "";
foreach my $a (@vdm_choisi_split) {
$tmp = $tmp." ".$a;
if ( length($tmp) >= $ARGV[0] ) {
$tmp =~ s/^\s//g;
$phrase_final = $phrase_final."\n".$tmp;
$tmp = "";
}
}
$tmp =~ s/^\s//g;
$phrase_final = $phrase_final."\n".$tmp;
$phrase_final =~ s/^\n//g;
$phrase_final =~ s/^\s//g;
$phrase_final =~ s/\"/\"/g;
$phrase_final = $phrase_final."\n";
return $phrase_final;
}
my $vdm_final = &vdm_get;
print $vdm_final;
Afficher un calendrier
il s'agit d'une version modifiée de celui ci : http://www.gladir.com/CODER/PERL/calendar.htm
#!/usr/bin/perl
use strict;
use warnings;
sub IsLeapYear($) {
my ($Year) = @_;
return ((($Year & 3) == 0) && (($Year % 100 != 0) || ($Year % 400 == 0)));
}
sub DateToDayOfWeek($$$) {
my ($Y,$M,$D) = @_;
if(($M > 12) || (0 == $M) || (0 == $D)) {
return 0;
}
if($Y < 0) {
$Y++;
}
my $T0 = int(0.6 + 1 / $M);
my $T1 = $M + 12 * $T0;
my $T2 = $Y - $T0;
my $Total = int(13 * ($T1 + 1) / 5) + int(5 * $T2 / 4) - int($T2 / 100) + int($T2 / 400) + $D - 1;
return $Total - 7 * int($Total / 7);
}
sub PutCalendar($$$) {
my ($Year,$Month,$Day) = @_;
my @Days = ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
if(&IsLeapYear($Year)) { $Days[2] = 29; }
my $D = &DateToDayOfWeek($Year, $Month, 1);
print "Diman Lundi Mardi Mercr Jeudi Vendr Samed\n";
print " " x (6 * $D);
for(my $I = 1;$I <= $Days[$Month]; $I++) {
print $I < 10 ? " " : "";
print $I," " x 4;
if (0 == ($D + $I) % 7) { print "\n"; }
}
}
my $time = time();
my ( undef, undef, undef, undef, $mois, $annee, undef, undef, undef ) = localtime($time);
$mois += 1;
$annee += 1900;
&PutCalendar($annee, $mois, 3);
Météo / Vent / Lune
necessite LWP ( certainement disponible dans vos dépots )
necessite Astro::Moonphase ( deja mis dans le fichier compressé )
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
use FindBin;
use Astro::MoonPhase;
my $dir = $FindBin::Bin;
my $result = 0;
my $ville = $ARGV[0];
my $link = get("http://www.google.com/ig/api?weather=".$ville."&hl=fr") or $result = 1;
my $db_file = $dir."/meteo.db";
my (undef,$moonillu,undef,undef,undef,undef,undef) = phase(time);
$moonillu = int($moonillu*100);
if ( $result ) {
open(FIC,">".$db_file);
print FIC "NA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\nNA\n";
close(FIC);
`rm -rf $dir/actual/*.png`;
`cp $dir/moon/$moonillu.png $dir/actual/moon.png`;
`cp $dir/maxi/undefined.png $dir/actual/j.png`;
`cp $dir/mini/undefined.png $dir/actual/j+1.png`;
`cp $dir/mini/undefined.png $dir/actual/j+2.png`;
`cp $dir/mini/undefined.png $dir/actual/j+3.png`;
`cp $dir/mini/undefined.png $dir/actual/j+4.png`;
`cp $dir/vent/undefined.png $dir/actual/vent.png`;
} else {
$link =~ s/\n//g;
$link =~ s/\t//g;
my $link2 = $link;
$link2 =~ s/.*<current_conditions>//;
$link2 =~ s/<\/current_conditions>.*//;
my ($temp_act,$icon_act,$wind_act) = ($link2,$link2,$link2);
$temp_act =~ s/.*<temp_c\sdata="(.*)"\/><humi.*/$1/;
$icon_act =~ s/.*icon\sdata="\/ig\/images\/weather\/(.*)\.gif"\/><wind.*/$1/;
$wind_act =~ s/.*wind_condition\sdata="Vent\s:\s(.*)\sà.*/$1/;
my $link3 = $link;
$link3 =~ s/<forecast_conditions>(.*)<\/forecast_conditions><forecast_conditions>(.*)<\/forecast_conditions><forecast_conditions>(.*)<\/forecast_conditions><forecast_conditions>(.*)<\/forecast_conditions>/$1=::=$2=::=$3=::=$4/;
my ( $jplus1,$jplus2,$jplus3,$jplus4 ) = ( split( "=::=",$link3));
my $jplus1_jour = $jplus1;
my $jplus1_temp_min = $jplus1;
my $jplus1_temp_max = $jplus1;
my $jplus1_ciel = $jplus1;
$jplus1_jour =~ s/.*_of_week\sdata="(.*)"\/><low\sdata.*/$1/;
$jplus1_temp_min =~ s/.*<low\sdata="(.*)"\/><high\sdata.*/$1/;
$jplus1_temp_max =~ s/.*<high\sdata="(.*)"\/><icon\sdata.*/$1/;
$jplus1_ciel =~ s/.*icon data="\/ig\/images\/weather\/(.*)\.gif"\/><condition\sdata.*/$1/;
my $jplus2_jour = $jplus2;
my $jplus2_temp_min = $jplus2;
my $jplus2_temp_max = $jplus2;
my $jplus2_ciel = $jplus2;
$jplus2_jour =~ s/.*_of_week\sdata="(.*)"\/><low\sdata.*/$1/;
$jplus2_temp_min =~ s/.*<low\sdata="(.*)"\/><high\sdata.*/$1/;
$jplus2_temp_max =~ s/.*<high\sdata="(.*)"\/><icon\sdata.*/$1/;
$jplus2_ciel =~ s/.*icon data="\/ig\/images\/weather\/(.*)\.gif"\/><condition\sdata.*/$1/;
my $jplus3_jour = $jplus3;
my $jplus3_temp_min = $jplus3;
my $jplus3_temp_max = $jplus3;
my $jplus3_ciel = $jplus3;
$jplus3_jour =~ s/.*_of_week\sdata="(.*)"\/><low\sdata.*/$1/;
$jplus3_temp_min =~ s/.*<low\sdata="(.*)"\/><high\sdata.*/$1/;
$jplus3_temp_max =~ s/.*<high\sdata="(.*)"\/><icon\sdata.*/$1/;
$jplus3_ciel =~ s/.*icon data="\/ig\/images\/weather\/(.*)\.gif"\/><condition\sdata.*/$1/;
my $jplus4_jour = $jplus4;
my $jplus4_temp_min = $jplus4;
my $jplus4_temp_max = $jplus4;
my $jplus4_ciel = $jplus4;
$jplus4_jour =~ s/.*_of_week\sdata="(.*)"\/><low\sdata.*/$1/;
$jplus4_temp_min =~ s/.*<low\sdata="(.*)"\/><high\sdata.*/$1/;
$jplus4_temp_max =~ s/.*<high\sdata="(.*)"\/><icon\sdata.*/$1/;
$jplus4_ciel =~ s/.*icon data="\/ig\/images\/weather\/(.*)\.gif"\/><condition\sdata.*/$1/;
open(FIC,">".$db_file);
print FIC $ville."\n".$temp_act."\n".$icon_act."\n".$wind_act."\n".$jplus1_jour."\n".$jplus1_temp_min."\n".$jplus1_temp_max."\n".$jplus1_ciel."\n".$jplus2_jour."\n".$jplus2_temp_min."\n".$jplus2_temp_max."\n".$jplus2_ciel."\n".$jplus3_jour."\n".$jplus3_temp_min."\n".$jplus3_temp_max."\n".$jplus3_ciel."\n".$jplus4_jour."\n".$jplus4_temp_min."\n".$jplus4_temp_max."\n".$jplus4_ciel."\n";
close(FIC);
`rm -rf $dir/actual/*.png`;
`cp $dir/moon/$moonillu.png $dir/actual/moon.png`;
`cp $dir/maxi/$icon_act.png $dir/actual/j.png`;
`cp $dir/mini/$jplus1_ciel.png $dir/actual/j+1.png`;
`cp $dir/mini/$jplus2_ciel.png $dir/actual/j+2.png`;
`cp $dir/mini/$jplus3_ciel.png $dir/actual/j+3.png`;
`cp $dir/mini/$jplus4_ciel.png $dir/actual/j+4.png`;
`cp $dir/vent/$wind_act.png $dir/actual/vent.png`;
}
Fête des Saints
ce script utilise l'api de : http://fetedujour.fr
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
my $result = 0;
my $link = get("http://fetedujour.fr/api/text") or $result = 1;
if ( $result ) {
print "NA\n";
} else {
$link =~ s/.*les\s(.*)\./$1/;
print $link."\n";
}
Afficher des flux rss
format :
perl <lien du flux> <longueur des titres> <nombre de titres>
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
use LWP::UserAgent;
if ( !defined($ARGV[0]) or !defined($ARGV[1]) or !defined($ARGV[2]) ) {
print "Error\n";
exit;
}
my ( $link,$lenght,$qte) = ($ARGV[0],$ARGV[1],$ARGV[2]);
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->agent('Mozilla/5.0');
my $response = $ua->get($link);
if ($response->is_success) {
my $dl = $response->decoded_content;
$dl =~ s/\n//g;
$dl =~ s/.*gif<\/url><link>http:\/\/www\.lemonde\.fr<\/link><\/image>(.*)/$1/;
$dl =~ s/<\/channel><\/rss>//;
$dl =~ s/<\/item>//g;
$dl =~ s/^<item>//;
my @list = split("<item>",$dl);
my $count = 0;
while ( $count < $qte ) {
my $tmp = $list[$count];
$count = $count + 1;
$tmp =~ s/<title>//g;
$tmp =~ s/<\/title>.*//g;
if ( length($tmp) <= $lenght ) {
print $tmp."\n";
} else {
my $tmp2 = $lenght - 3;
$tmp =~ s/(.{$tmp2}).*/$1\.\.\./;
print $tmp."\n";
}
}
} |