Affichage des articles dont le libellé est cmdline. Afficher tous les articles
Affichage des articles dont le libellé est cmdline. Afficher tous les articles

mercredi 6 octobre 2021

mardi 5 octobre 2021

Shell tools : shellcheck


  • ShellCheck, a static analysis tool for shell scripts

https://github.com/koalaman/shellcheck



suggests to add this on your makefiles :

check-scripts:
    # Fail if any of these files have warnings
    shellcheck myscripts/*.sh
or this on your CI (here : .travis.yml )
script:
  # Fail if any of these files have warnings
  - shellcheck myscripts/*.sh



lundi 26 octobre 2015

Scripting : set variables depending how the where launched (terminal mode, cron/auto mode, ...)

You all know the deal : when you launch a command it (obviously) comes with all your environment variables. But when you want to cron it, none of them is present. We hence want to set some variables, but only in some cases. The "tty" command will help us do so.


You can use the tty tool to check if a script is called from the standard output :


if ! tty -s
then
    exec >/dev/null 2>&1
else
    MAIL_DEST="email@server.ext"
fi



  • The command tty returns :

User Commands                                              tty(1)

NAME
     tty - return user's terminal name

SYNOPSIS
     tty [-l] [-s]

DESCRIPTION
     The tty utility writes to the standard output  the  name  of
     the  terminal  that is open as standard input. The name that
     is used is equivalent to the string that would  be  returned
     by the ttyname(3C) function.

OPTIONS
     The following options are supported:

     -l       Prints the synchronous line  number  to  which  the
              user's terminal is connected, if it is on an active
              synchronous line.

     -s       Inhibits printing of the terminal path name, allow-
              ing one to test just the exit status.

EXIT STATUS
     The following exit values are returned:

     0        Standard input is a terminal.

     1        Standard input is not a terminal.

     >1       An error occurred.

 

mardi 2 juin 2015

Replace all occurences of a string in a bunch of files by another string (in place)


  • Find all files on containing STRING_AAAA and replace it by STRING_BBBB in place (directly in the file).
find . -type f -exec grep -l STRING_AAAA {} \; -exec perl -pi -e 's!STRING_AAAA!STRING_BBBB!g' {} \;
Pre-tests :
  • Find all files on containing STRING_AAAA.
find . -type f -exec grep -l STRING_AAAA {} \;

mercredi 11 février 2015

awk 'system()' vs xargs

Two different syntaxes for processing a command over a list of arg.

Let's take for example, the list of PID you want to kill(all the processes matching "toto") :

ps | grep toto | awk -F' ' '{print $2}' | xargs kill -9

is equivalent to

ps | grep toto | awk -F' ' '{system("kill -9 "$2}'

note that the space at the end of the string "kill -9 " is important since the $2 will be concatenated.

jeudi 12 juillet 2012

Command(s) of the day

Some colleagues started putting commands on the white-board every X days under
  • comm compare two sorted files line by line
  • paste merge lines of files
  • colordiff diff, with colors
  • colorgcc
  • pgrep look for a process name
  • pkill kill processes by name, not by pid
  • ...

dimanche 23 août 2009

live network trafic view ? iptraf, iftop

A explorer

http://www.commentcamarche.net/faq/sujet-848-linux-trafic-entrant-sortant-en-temps-reel


On trouvera ci dessous les extraits des deux manpages de iptraf et ethstatus.
Intéressant pour comptabiliser la quantité de données qui circulent sur les différentes interfaces, ainsi que pour monitorer quelles sont les connexions ouvertes.

Après un bref test, "ethstatus" m'a cependant l'air d'utiliser beaucoup de ressources CPU, et semble être surtout un reformatage des infos d'ifconfig. Peu intéressant donc.

Au contraire, "iptraf" était plus léger et apportait plus d'informations.

Egalement, iftop fourni plus d'informations et permet de lister les connextions courantes un peu comme "top" le ferait.






IPTRAF(8) IPTRAF(8)

NAME
iptraf - Interactive Colorful IP LAN Monitor

SYNOPSIS
iptraf { [ -f ] [ -q ] [ -u ] [ { -i iface | -g | -d iface | -s iface |
-z iface | -l iface } [ -t timeout ] [ -B [ -L logfile ] ] ] | [ -h ] }

DESCRIPTION
iptraf is an ncurses-based IP LAN monitor that generates various net‐
work statistics including TCP info, UDP counts, ICMP and OSPF informa‐
tion, Ethernet load info, node stats, IP checksum errors, and others.

If the command is issued without any command-line options, the program
comes up in interactive mode, with the various facilities accessed
through the main menu.



IFTOP(8) IFTOP(8)

NAME
iftop - display bandwidth usage on an interface by host

SYNOPSIS
iftop -h | [-nNpbBP] [-i interface] [-f filter code] [-F net/mask]

DESCRIPTION
iftop listens to network traffic on a named interface, or on the first
interface it can find which looks like an external interface if none is
specified, and displays a table of current bandwidth usage by pairs of
hosts. iftop must be run with sufficient permissions to monitor all
network traffic on the interface; see pcap(3) for more information, but
on most systems this means that it must be run as root.

By default, iftop will look up the hostnames associated with addresses
it finds in packets. This can cause substantial traffic of itself, and
may result in a confusing display. You may wish to suppress display of
DNS traffic by using filter code such as not port domain, or switch it
off entirely, by using the -n option or by pressing R when the program
is running.

By default, iftop counts all IP packets that pass through the filter,
and the direction of the packet is determined according to the direc‐
tion the packet is moving across the interface. Using the -F option it
is possible to get iftop to show packets entering and leaving a given
network. For example, iftop -F 10.0.0.0/255.0.0.0 will analyse packets
flowing in and out of the 10.* network.

jeudi 16 juillet 2009

Jgraph, command line tool for graphics

Command-line graph production.

The input describe some plotting or curving with a language quite straightforward to read and write, and produces an image (ps, eps, gif, ...).


Main Website :
http://www.cs.utk.edu/~plank/plank/jgraph/jgraph.html

Some examples & first hands on Jgraph :
http://www.cs.utk.edu/~plank/plank/classes/cs494/494/notes/Jgraph/lecture.html

"Brief Description"
"Jgraph is a program that takes the description of a graph or graphs as input, and produces a postscript file on the standard output. Jgraph is ideal for plotting any mixture of scatter point graphs, line graphs, and/or bar graphs, and embedding the output into LaTeX, or any other text processing system that can read postscript. "


There are 2 JGraph, and the most referenced on the web search engines is a Java library. This is obviously NOT about that jgraph...

mardi 21 avril 2009

date relative

Utilisation de la commande date pour calculer une date relative en nombre d'heures à partir d'une autre date.

  1. 1ère étape : entrer la date initiale avec date
    $ date --date='2009-03-23 12:00'


  2. 2ème étape : utiliser le résultat obtenu comme base pour y ajouter un décalage en nombre d'heures, soit donc :
    $ date --date="$(date --date='2009-03-23 12:00') +1001 hours"
    Mon May 4 06:00:00 CEST 2009



mercredi 1 avril 2009

convert .wmv to .avi

mencoder infile.wmv -ofps 23.976 -ovc lavc -oac copy -o outfile.avi

mercredi 4 mars 2009

commandlinefu

Fantastique !

http://www.commandlinefu.com

c'était un peu l'idée de ce blog au départ, bien que cela ait un peu dévié...

En se retrouve sur ce site avec un équivalent twitter, mais uniquement pour des lignes de commande !

exemple, cette commande que j'avais eu l'occasion de chercher un jour pour une vidéo prise avec mon appareil photo...
mencoder -vf rotate=1 -ovc lavc -oac copy "$1" -o "$1"-rot.avi

dimanche 6 mai 2007

bluetooth in range

Pour lister les périphériques bluetooth détectés dans le voisinage, plusieurs solutions :
  • hcitool scan
    # hcitool scan Scanning ... 00:xx:xx:xx:xx:xx Phone
  • hcitool inq
    # hcitool inq Inquiring ... 00:xx:xx:xx:xx:XX clock offset: 0x1yyy class: 0x5zzzzz
http://wiki.ubuntu-fr.org/tutoriel/bluetooth-edgy http://doc.ubuntu-fr.org/materiel/bluetooth http://multisync.sourceforge.net/