Re: Is perl still the No.1 language for sysadmin?
Michel Verdier wrote:
> #!/usr/bin/perl -w
>
> use strict;
>
> # echo $PATH | tr ':' '\n' | perl -MFile::Slurp -ne 'chomp;@e=read_dir($_,prefix=>1); print map "$_\n",@e'|xargs file|perl -pe 's/\S+\s+//'|grep -v 'symbolic link'|perl -pe 's/, dynamically linked.+//'|sort|uniq -c|sort -rn
>
> my @folders = split(':',$ENV{PATH});
> my %count;
>
> foreach my $folder (@folders) {
> chomp($folder);
> next if(-l $folder);
> print "$folder\n";
> opendir(DIR,"$folder");
> my @files = readdir(DIR);
> closedir DIR;
> foreach my $file (@files) {
> next if($file =~ /^\.\.?$/ or -l "$folder/$file");
> chomp(my $type = `file -b $folder/$file`);
> next if($type =~ /symbolic link/);
> $type =~ s/,.+$//;
> $count{$type}++;
> }
> }
>
> foreach my $key (sort {$count{$b} <=> $count{$a}} keys %count) {
> printf("%5d %s\n", $count{$key}, $key);
> }
First, the syntax is much nicer than Python ...
Question: Can you do everything with Perl, with zsh you can't
and it is annoying and you also feel silly asking people stuff
how you do that and putting them in a position they have to
say "You can't do that". With Lisp you can do everything,
I sort of got used to it, you know what I'm saying?
Check out my Perl BTW, is it any good? Not really, right?
Haha, ah, wrote it to get a job, one thousand years ago, and
didn't get it BTW, back then I always drank one beer before
the interviews to get relaxed, and one energy drink to get
focused LOL
Anyway here
https://dataswamp.org/~incal/note_DB
So the syntax, maybe that's huge part of not liking
Python intuitively?
Man, to be honest I didn't know this focus on text with Perl,
if I had, maybe I would have done that from the start because
obviously that's something you do all the time.
But OTOH it was fun fiddling with awk, sed, perl ...
Ha, right, let me look that up, 2 instances ...
perl -e '1 while 1'
What's that's suppose to mean? This file:
https://dataswamp.org/~incal/conf/.zsh/cpu
And exact same line here (last).
Ah, it's like to stress the processor or something speaking of
CPU instructions.
Anyway what I wanted to say, since text processing is so
fundamental one is maybe recommended to learn great Perl
actually than to collect little fragments from awk, sed, perl
as a shell to LOL, that's why I don't write it with a capital
P, no, but really, I mean superficial use, instead learn
Pearl, in the list should also be included like zsh, not to
mention - I'll not mention them - all the shell tools.
Was it fun fiddling with them? Yes. Did it work? Yes, but not
really fluently. Does it ever? Well ... no :)
#! /bin/zsh
#
# this file:
# https://dataswamp.org/~incal/conf/.zsh/temp
temp-gov () {
local t=100
local cpu
local cpu_min
local cpu_max
perl -e '1 while 1' &
local pid=$!
sleep 10
local i
local g
for g in $(cpufreq-info -g); do
sudo cpufreq-set -g $g
cpu_min=999
cpu_max=0
for i in {0..$t}; do
cpu=$(sensors -j | jq -a '.["k10temp-pci-00c3"].Tdie.temp1_input')
(( $cpu < $cpu_min )) && cpu_min=$cpu
(( $cpu > $cpu_max )) && cpu_max=$cpu
done
printf "CPU C (%.2f %.2f) (%d iterations) %s\n" $cpu_min $cpu_max $t $g
done
kill $pid
}
temperature () {
local cpu_min=999
local gpu_min=999
local cpu_max=0
local gpu_max=0
local cpu
local gpu
while true; do
cpu=$(sensors -j | jq -a '.["k10temp-pci-00c3"].Tdie.temp2_input')
gpu=$(sensors -j | jq -a '.["nouveau-pci-0100"].temp1.temp1_input')
(( $cpu > $cpu_max )) && cpu_max=$cpu
(( $gpu > $gpu_max )) && gpu_max=$gpu
(( $cpu < $cpu_min )) && cpu_min=$cpu
(( $gpu < $gpu_min )) && gpu_min=$gpu
printf "CPU %.1fC (%.1f %.1f)\nGPU %.1fC (%.1f %.1f)\n\n" \
$cpu $cpu_min $cpu_max \
$gpu $gpu_min $gpu_max
sleep 1
done
}
alias {fan,fans}=temperature
--
underground experts united
https://dataswamp.org/~incal
Reply to: