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.
mercredi 11 février 2015
mardi 10 février 2015
while true for WPS
While true permettant de se connecter dès que quelqu'un initie une connexion avec du WPS
http://korben.info/intrusion-dans-un-reseau-wifi-grace-au-wps.html?utm_source=feedburner&utm_medium=email&utm_campaign=Feed:+Korben_nl+%28Korben%29
wpa_cli
while : ; do sudo wpa_cli wps_pbc any ; sleep 120 ; done &
Source :http://korben.info/intrusion-dans-un-reseau-wifi-grace-au-wps.html?utm_source=feedburner&utm_medium=email&utm_campaign=Feed:+Korben_nl+%28Korben%29
lundi 26 janvier 2015
Find big files
In the current path, find all files bigger than, let's say 10MiB (10^7Bytes).
$ find . -type f -size +10000000c -exec ls -l {} \;
$ find . -type f -size +10000000c -exec ls -l {} \;
samedi 8 novembre 2014
How to store you passwords
a little tutorial on how to use bcrypt to store your passwords
https://medium.com/@martyweiner/store-your-users-passwords-correctly-c155ac90f0c2
https://medium.com/@martyweiner/store-your-users-passwords-correctly-c155ac90f0c2
mercredi 29 octobre 2014
port install error "checksum does not exist" : clean and reinstall
I had an error with the Mac Ports (https://www.macports.org/) on the dbus-glib install while trying to install some other packages. It was just saying that it did not exist in /opt/local/var/macports/distfiles/dbus-glib . It's not clear what broke this package for now, but the way to solve the issue was simple as found here : https://trac.macports.org/ticket/45534
sudo port clean
and then, reinstall...
sudo port install
And check, I could upgrade all the other packages and install some other new ones :-)
---
(For "google" parse purpose, here are the errors I was getting)
---
[...]
---> Found 5 broken port(s), determining rebuild order
---> Rebuilding in order
libgnomeui @2.24.5 +x11
net-snmp @5.7.2
webkit-gtk @2.0.4 +video
gimp2 @2.8.6 +help_browser+python27
xsane @0.998
---> Computing dependencies for dbus-glib
---> Verifying checksums for dbus-glib
Error: org.macports.checksum for port dbus-glib returned: dbus-glib-0.102.tar.gz does not exist in /opt/local/var/macports/distfiles/dbus-glib
Please see the log file for port dbus-glib for details:
/opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_devel_dbus-glib/dbus-glib/main.log
Error: Unable to upgrade port: 1
Error rebuilding libgnomeui
while executing
"error "Error rebuilding $portname""
(procedure "revupgrade_scanandrebuild" line 395)
invoked from within
"revupgrade_scanandrebuild broken_port_counts $opts"
(procedure "macports::revupgrade" line 5)
invoked from within
"macports::revupgrade $opts"
(procedure "action_revupgrade" line 2)
invoked from within
"action_revupgrade $action $portlist $opts"
(procedure "action_target" line 96)
invoked from within
"$action_proc $action $portlist [array get global_options]"
(procedure "process_cmd" line 93)
invoked from within
"process_cmd $remaining_args"
invoked from within
"if { [llength $remaining_args] > 0 } {
# If there are remaining arguments, process those as a command
set exit_status [process_cmd $remaining..."
(file "/opt/local/bin/port" line 5254)
jeudi 9 octobre 2014
JavaScript multiline code (JSON description)
It is currently not possible to store a multiline string in javascript. This is annoying since for example storing some JSON data often leads to long data to concatenate or to push into an array.
If you want to avoid this, you can use the following trick, since javascript accepts multiline comments, and returns them to the toString call on a function :
Note 2 :
ECMA-262 5th Edition section 7.8.4 and called LineContinuation : "A line terminator character cannot appear in a string literal, except as part of a LineContinuation to produce the empty character sequence. The correct way to cause a line terminator character to be part of the String value of a string literal is to use an escape sequence such as \n or \u000A."
Note 3 :
"In EcmaScript 6, you'll be able to use backticks for Template Strings, known in the spec as a NoSubstitutionTemplate:
(seen on : http://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript)
If you want to avoid this, you can use the following trick, since javascript accepts multiline comments, and returns them to the toString call on a function :
var jsonDescriptionText= function(){/*
[
{
"cat": "Categ1",
"links": [
{
"txt": "text1",
"url": "http://url",
"title": "mouseover field"
}
]
}
]*/}.toString().slice(14,-3);
Note 1 :
This avoids using concatenation for each line :
var longString2="string part1" +
"string part2"or even escaping the new lines :
var longString2="string part1\
string part2"
Note 2 :
ECMA-262 5th Edition section 7.8.4 and called LineContinuation : "A line terminator character cannot appear in a string literal, except as part of a LineContinuation to produce the empty character sequence. The correct way to cause a line terminator character to be part of the String value of a string literal is to use an escape sequence such as \n or \u000A."
Note 3 :
"In EcmaScript 6, you'll be able to use backticks for Template Strings, known in the spec as a NoSubstitutionTemplate:
var htmlString = `Say hello to
multi-line
strings!`;
"(seen on : http://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript)
Labels:
ECMA,
javascript,
js,
JSON,
multiline
mardi 19 août 2014
Code Style
This tools allows you to reformat your code in order to respect some particular coding rules.
This is for example what you want to use as a trigger in your svn, git or clearcase repo ;-)
http://astyle.sourceforge.net/
This is for example what you want to use as a trigger in your svn, git or clearcase repo ;-)
http://astyle.sourceforge.net/
vendredi 8 août 2014
KSH eval / variable subtitution / variable test
from :http://b62.tripod.com/doc/docksh.htm
OTHER FUNCTIONALITIES
cmd1 || cmd2 exec cmd2 if cmd1 fail cmd1 && cmd2 exec cmd2 if cmd1 is OK V1=${V2:=V3} Set V1 with the value of V2 if this is set else set the variable V1 with value of V3 (V3 could be a number). sh replacement: if [ $V2 ] ; then V1=$V2 else V1=$V3 Example: DisplaySize=${LINES:24} ; Command=${Command:"cat"} ${V1:?word} if V1 set & V1!=null ret $V1 else print word and exit : ${V1:?"variable V1 not set on null"} ${V1:=word} if V1 !set | V1==null set V1=$word ${V1:-word} if V1 set & V1!=null ret $V1 else ret word ${V1:+word} if V1 set & V1!=null ret word else ret nothing ${V1##patt} ${V1#patt} if patt are found at the begin of V1 return V1 whitout the patt else return V1 V1="lspwd" ; ${V1#"ls"} # exec pwd ${V1%%patt} ${V1%patt} if patt are found at the end of V1 return V1 whitout the patt else return V1 V1="lspwd" ; ${V1%"pwd"} # exec ls
from : http://www.well.ox.ac.uk/~johnb/comp/unix/ksh.html
Removing something from a variable
Variables that contain a path can very easily be stripped of it: ${name##*/} gives you just the filename.Or if one wants the path: ${name%/*}. % takes it away from the left and # from the right.
%% and ## take the longest possibility while % and # just take the shortest one.
Replacing a variable if it does not yet exits
If we wanted $foo or if not set 4 then: ${foo:-4} but it still remains unset. To change that we use:${foo:=4}
Exiting and stating something if variable is not set
This is very important if our program relays on a certain vaiable: ${foo:?"foo not set!"}Just check for the variable
${foo:+1} gives one if $foo is set, otherwise nothing.KSH : $- and Flags
Under Solaris and using the Korn Shell KSH, the $- allows access to the flags setted.
Example of how it changes when setting the debug mode '-x' :
man ksh informs us that (cf. http://www.lehman.cuny.edu/cgi-bin/man-cgi?ksh+1 for example)
" - " Correspond to the "Flags supplied to the shell on invocation or by the set command." and that "The current set of flags can be found in $- ":
Example of how it changes when setting the debug mode '-x' :
# echo $- ismC # set -x # echo $- + echo isxmC isxmC # set +x
man ksh informs us that (cf. http://www.lehman.cuny.edu/cgi-bin/man-cgi?ksh+1 for example)
" - " Correspond to the "Flags supplied to the shell on invocation or by the set command." and that "The current set of flags can be found in $- ":
Parameters Set by Shell - Flags supplied to the shell on invocation or by the set command. set [ _abCefhkmnopstuvx ] [ _o option ]... [ _A name ] [ arg ... ] The flags for this command have meaning as follows: -A Array assignment. Unsets the variable name and assigns values sequentially from the list arg. If +A is used, the variable name is not unset first. -a All subsequent variables that are defined are automatically exported. -b Causes the shell to notify the user asyn- chronously of background job completions. The following message is written to standard error: "[%d]%c %s%s\n",, , , \ where the fields are as follows: The character + identifies the job that would be used as a default for the fg or bg utilities. This job can also be specified using the job_id %+ or %%. The charac- ter - identifies the job that would become the default if the current default job were to exit; this job can also be speci- fied using the job_id %-. For other jobs, this field is a space character. At most one job can be identi- fied with + and at most one job can be identified with -. If there is any suspended job, then the current job is a suspended job. If there are at least two suspended jobs, then the previous job is also a suspended job. A number that can be used to identify the process group to the wait, fg, bg, and kill utilities. Using these utilities, the job can be identified by prefixing the job number with %. Unspecified. Unspecified. When the shell notifies the user a job has been completed, it can remove the job's pro- cess ID from the list of those known in the current shell execution environment. Asyn- chronous notification is not enabled by default. -C Prevents existing files from being overwrit- ten by the shell's > redirection operator. The >| redirection operator overrides this noclobber option for an individual file. -e If a command has a non-zero exit status, executes the ERR trap, if set, and exit. This mode is disabled while reading pro- files. -f Disables file name generation. -h Each command becomes a tracked alias when first encountered. -k All variable assignment arguments are placed in the environment for a command, not just those that precede the command name. -m Background jobs runs in a separate process group and a line prints upon completion. The exit status of background jobs is reported in a completion message. On systems with job control, this flag is turned on automati- cally for interactive shells. -n Reads commands and check them for syntax errors, but do not execute them. Ignored for interactive shells. -o Writes the current option settings to stan- dard output in a format that is suitable for reinput to the shell as commands that achieve the same option settings. -o The following argument can be one of the following option names: allexport Same as -a. errexit Same as -e. bgnice All background jobs are run at a lower priority. This is the default mode. emacs Puts you in an emacs style in-line editor for command entry. gmacs Puts you in a gmacs style in- line editor for command entry. ignoreeof The shell does not exit onEOF. The command exit must be used. keyword Same as -k. markdirs All directory names resulting from file name generation have a trailing / appended. monitor Same as -m. noclobber Prevents redirection > from truncating existing files. Require >| to truncate a file when turned on. Equivalent to -C. noexec Same as -n. noglob Same as -f. nolog Do not save function defini- tions in history file. notify Equivalent to -b. nounset Same as -u. privileged Same as -p. verbose Same as -v. trackall Same as -h. vi Puts you in insert mode of a vi style in-line editor until you hit escape character 033. This puts you in control mode. A return sends the line. viraw Each character is processed as it is typed in vi mode. xtrace Same as -x. If no option name is supplied, the current option settings are printed. -p Disables processing of the $HOME/.profile file and uses the file /etc/suid_profile instead of the ENV file. This mode is on whenever the effective uid is not equal to the real uid, or when the effective gid is not equal to the real gid. Turning this off causes the effective uid and gid to be set to the real uid and gid. -s Sorts the positional parameters lexicograph- ically. -t Exits after reading and executing one com- mand. -u Treats unset parameters as an error when substituting. -v Prints shell input lines as they are read. -x Prints commands and their arguments as they are executed. - Turns off -x and -v flags and stops examin- ing arguments for flags. -- Does not change any of the flags. Useful in setting $1 to a value beginning with -. If no arguments follow this flag then the posi- tional parameters are unset. Using + rather than - causes these flags to be turned off. These flags can also be used upon invocation of the shell. The current set of flags can be found in $-. Unless -A is specified, the remaining arguments are positional parameters and are assigned, in order, to $1 $2 .... If no arguments are given, the names and values of all variables are printed on the standard output.
mercredi 23 juillet 2014
find + mv
find ./ -name "*.logfile" | xargs -i mv '{}' /my/really/great/implementation_scripts/log_directory/
(cf : http://bturnip.com/weblog/?p=248 )
or :
find ./ -name "*.logfile" -exec mv '{}' /my/really/great/implementation_scripts/log_directory/ \;
Inscription à :
Articles (Atom)