Cerca qui le cose strambe

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

2025-04-24

grep di stdin tenendo l'header

 

A volte puo` essere utile un grep di stdin tenendo l'header

Si definisce in bash (nel .bashrc o simile) una funzione cortissima tipo cosi` =>


hgrep () { read line; echo "$line"; grep $* ; }


ci sono rari casi in cui puo` essere  leggermente pericolosa, ma nel complesso pare accettabile


esempio d'uso:



# lsof   | hgrep  tripwire
COMMAND       PID     TID TASKCMD              USER   FD      TYPE             DEVICE    SIZE/OFF       NODE NAME
tripwire  2285668                              root  cwd       DIR              253,0       36864     524292 /root
tripwire  2285668                              root  rtd       DIR              253,0        4096          2 /
tripwire  2285668                              root  txt       REG              253,0     3140528        594 /usr/sbin/tripwire
tripwire  2285668                              root    4u      REG              253,3    51822592         36 /tmp/twtempUYqaRJ (deleted)
#
# ps aux | hgrep /usr/sbin/tripwire
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     2285668 96.1  1.4 484084 467676 ?       R    14:45  16:33 /usr/sbin/tripwire
#  



2025-04-09

mp3 not accepted by audacity

 in case you are trying to import an mp3 file with Audacity and it fails with error "incorrect filetype"




you can check it with the file command line tool in cywin/Linux/etc

$ file ./somefile.mp3

./somefile.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, JntStereo

$

after some googling it turned out that a simple fix is using mp3validate 

https://mp3val.sourceforge.net/

(binaries available for windows/linux/etc)

for Debian/Ubuntu you should be able to use a plain

sudo apt install mp3val in case you do want to proceed with fixing the file without creating  a backup you can simply launch this command: mp3val somefile.mp3 -f -nb and then boom - Audacity will be happy in importing it.

2024-10-15

how to fix "sudo su -" when it has become slow in starting

in case someone is wondering why, from time to time, on a linux server the command 

sudo su -

 seems stuck or just much slower than normal in starting..  this may be because  when the command 

 sudo su -

is starting, by default it scans   wtmp to report last login time from user root and, if on such servers there are hundreds of users, last root access entry may be deep in the access list 

 
the quick trick I have found to fix it is to launch first a simple 

sudo bash 

(so a new entry for root is reported at the top of wtmp) and then closing it at once - after that any next 

sudo su - 

returns to be as fast as usual

2021-12-21

Come recuperare maptools per Ubuntu Linux in poco tempo

Per chi ha bisogno di aggiornare frequentemente maptools su Ubuntu Linux all'ultima release
non ci sono repository che tengano

Allora si puo`   scaricare a mano il .deb
ma tipicamente per ~200MB github ci impiega ~20/30 minuti...

alla fine ho deciso di chiedere a Google e scopro che c'e` un post su stackoverflow



...
I found a solution that worked very well for me.

Go to github and copy the link to the clipboard. Then open a web proxy website
( https://www.proxysite.com worked for me) and paste the link (I tried with US1) - instead of downloading 670mb in 1+ hour at least, it took less than 2 minutes.
...



Ovviamente ho provato subito e confermo che anche a me ha scaricato  ad una buona velocita` (~1.4Mbyte/s)



2021-12-16

Creare PDF fronte retro scansionando dall'ADF che legge una faccia sola

Supponiamo abbiate una stampante multifuzione con la possibilità di scansionare in PDF, attraverso una semplice interfaccia web,  un documento di più fogli dall'alimentatore automatico (ADF), con la limitazione di non supportare il caso di documenti stampati "fronte-retro".

Normalmente nel caso abbiate bisogno di acquisire dei fogli stampati anche sul retro sareste costretti a stampare tutti i retro (le pagine paro) e poi intercalandoli alle pagine dispari del documento originale scansionare tutti i fogli, oppure se foste più environment-friendly potreste scansionare ogni facciata singolarmente e poi assemblare manualmente dal laptop tutti i documenti in uno solo.

Per fortuna esiste una soluzione molto più semplice e comoda: 

  1. scansionare le facciate A in una passata sola di tutto il documento tramite l'ADF e salvare il PDF ottenuto (con le sole pagine 1,3,5,7 etc) come scan-front.pdf
  2. invertire il documento in modo che presenti tutte le pagine pari e poi sul retro le dispari (quindi  pag 2 con la 1 sul retro, pag 4 con la 3 sul retro etc etc)
  3. scansionare con l'ADF quelle facciate pari salvando il documento scan-rear.pdf
  4. rimettere a posto le pagine documento (passo ovvio, ma che può salvare parecchi mal di testa)
  5. usare il tool pdftk per interporre le pagine dei 2 pdf - ossia nel caso specifico:
     
    pdftk A=scan-rear.pdf B=scan-front.pdf  shuffle B A  output collated.pdf



Addirittura si può semplificare ulteriormente chiedendo a pdftk di prendere le pagine pari in ordine inverso: 


  1. scansionare le facciate A in una passata sola di tutto il documento tramite l'ADF e salvare il PDF ottenuto (con le sole pagine 1,3,5,7 etc) come scan-front.pdf
  2. prendere il plico di fogli usciti dall'ADF e ri-sottometterlo  all'ADF al fine di scansionare le facciate pari in ordine inverso, salvando il documento scan-rear.pdf
  3. usare il tool pdftk per interporre le pagine dei 2 pdf invertendo l'ordine delle pari (dopo la lettera "placeholder" del file si specifica il range "end-1"):
     
    pdftk A=scan-rear.pdf B=scan-front.pdf  shuffle B Aend-1  output collated.pdf


Si ringraziano sia pdftk che questo chiarissimo post su unix.stackexchange.com

NB: la procedura e` stata testata su Linux, ma esiste una versione free di pdftk anche per Windows

2021-05-04

Audacity e audio in cuffia in ubuntu

Se dopo aver lanciato Audacity l'audio in cuffia sparisce
e non torna nemmeno dopo aver chiuso l'applicazione, ma solo dopo aver tolto e rimesso il jack delle cuffie...
Ecco... facendo quasi come suggerito qui potreste aver bisogno di cambiare le impostazioni di Audacity
"default: Headphone Mic:0" in "pulse: Internal Mic:0"

2019-12-12

fans always at max speed on xps 15 with Ubuntu linux

since the installation I was not happy about the fan management on my Ubuntu 18: the temperatures were always too high despite the fans were running at more than 4000 RPM (often even more than 5000).

After several months where all my attempts went from bad to worse,
I ended up on this page

 so, long story short:

  1. launch the GUI nvidia-settings  
  2. select the Prime Profiles
  3. switch to Intel GPU
  4. then I was requested to reboot but I preferred also to add another change suggested at this other post
  5. I created as root the file /etc/modprobe.d/nvidia-user-registry.conf with just a single entry

    options nvidia NVreg_RegistryDwords="OverrideMaxPerf=0x2"
    
  6. and finally

    $ sudo update-initramfs -u
    $ sudo shutdown -r now
after the reboot the system is 100% fine - the fan speed is almost always less than 3000 RPM and the temperatures all below 55.0°C

2019-02-26

if df starts lagging

in case you df command starts lagging for 10~20 seconds you can use strace as per this article
$ strace /bin/df
basically what I have found is that one of the mapped resources took ~10 seconds to timeout changed IP from the last time I mounted it and so umounting and remounting fixed it

2018-10-12

rumore di fondo con cuffie wireless DECT in ubuntu

se vi capita di sentire un forte rumore di fondo quando usate delle cuffie DECT con ubuntu...

potrebbe essere che dovete abbassare il volume del device che e` al 100% (mentre il generale non e` sopra il 20/30%)
nel caso potete seguire la procedura come spiegata meglio qui

  1. lanciate il comando in ascii graph
    alsamixer
  2. passate al device in questione
  3. abbassate il volume
  4. uscite
  5. per registrare il cambiamento lanciate
    sudo alsactl store
  6. non ho ancora verificato che al reboot successivo la modifica sia stata mantenuta... ma l'articolo che ho trovato e` di 4 mesi fa quindi mi auguro che abbiano gia` rilasciato la patch relativa :-)

2018-10-08

provide automatic keyboard and mouse input in X

Do you need programmatically schedule some keyboard and mouse input in linux?
Look no further
xdotool is the solution :-)
the installation is as easy as typing

sudo apt-get install xdotool

and assuming you need to do a (left) click on the mouse but only 10 seconds after you left your desk:

sleep 10 ; xdotool click 1

Bonus
obviously it also work if you have to send the commands in a RDP session :-)

2018-02-15

how to fix midnight commander font in putty

If you are connecting from windows to a linux box with putty it may happen to you when you launch midnight commander that the graphical borders are rendered with odd characters the solution can be found in this article long story short:
  • right click on the putty top bar
  • select change Settings...
  • in the Putty Reconfiguration windows expand the tree structure on the left to Windows -> Translation
  • in the right pane click the Received data... drop-down list and select UTF-8
  • close and reopen midnight commander

2012-10-11

l'hardware e` mio e sono libero

...di farci girare Linux o altro

questo è il messaggio che sembra trasparire da una notizia che leggo
a questa pagina

the foundation will obtain a key from Microsoft and sign a small pre-bootloader. This will chain load a pre-designated bootloader without any check for a signature and in turn will allow the booting of any operating system

insomma: il cartello windows8HW di M$ ha stufato e M$ non lo capisce... almeno cominciamo ad aggirare il problema - la Linux Foundation comprerà una chiave uefi e creerà un bootloder (o forse detto meglio un chainloader) per tutti noi - Evviva!

2010-11-10

linux live cd: silenziare il cd che riparte ciclicamente

oggi stavo dovevo usare un cd live di un antivirus per debellare un malware dal pc di un amico e mi sono accorto che una paio di volte al minuto il lettore cd partiva per una quindicina di secondi e poi si quietava (faceva il cosidetto spinning del cd).

Siccome il rumore era notevole e avendo notato che comunque la distribuzione all'atto del caricamento si premura di allocare in ram l'immagine del disco mi sono armato di google e pazienza ed ho cominciato a cercare in rete con le chiavi che ritenevo più adatte ("noisy cd", "gentoo").

Dopo una dozzina di minuti infruttuosi sono giunto alla conclusione che non fosse un bug della distribuzione in uso perciò ho provato a cercare tra i processi in esecuzione un nome significativo (mentre l'antivirus era ancora a meno di un quarto della lettura dell'hard-disk - tempo ne avevo da vendere).

Leggendo l'output di

ps aux | less


mi sono imbattuto in un piccolo processo spind. L'utility file mi rassicurava trattarsi appunto di uno script di shell. Il breve testo dello script
ha confermato i miei sospetti: è uno script che ogni 30 secondi legge un byte a caso dal supporto nel drive (forse per tenerlo sveglio ed evitare che il cd venga smontato... o qualcosa del genere).

La vera domanda ora era se era possibile stopparlo in maniera pulita e soprattutto se non si corresse il pericolo di dar fastidio all'antivirus (sempre in esecuzione).

Fidandomi della mia ipotesi di una live totalmente già in ram e cercando ancora con google ho scoperto dell'esistenza di un micro script sotto init.d che si occupa di arrestare e avviare il suddetto daemon di spinning del cd ovviamente sotto /etc/init.d/spind.init

ovviamente a questo punto è stato immediato leggerne il contenuto e da qui rilvare il funzionamento standard


/etc/init.d/spind.init stop


e con questo il cd non fa più quel fastidioso rumore di elicottero in decollo per 120 volte all'ora :-DDD