run sudo, ssh, password, su in simulated interactive mode

Some commands do not like non-interactive mode $ passwd <<EOF > oldpassword > newpassword > newpassword > EOF Changing password for user lsc. Current password for lsc@example.com: passwd: Authentication token manipulation error $ echo oraclepassword | su – oracle standard in must be a tty $ echo sudopassword | sudo su – oracle [sudo] password […]

fun with cron

Today I find out that my scheduler was too busy to execute all jobs in my crontab !? * * * * * (while :;do ssh example.com :; done) 59 23 19 06 * touch /tmp/bang my while loop is going to produce so much hangs on the cron deamon that it may not be […]

How to quit crontab -e without overwritting cron

Imagine my crontab * * * * * /usr/bin/date > /tmp/foo I am writing the date to /tmp/foo every minute $  cat /tmp/foo Thu Jul  5 08:45:01 CEST 2012 Now I want to view my crontab in my EDITOR (vi). $ crontab -e I do not quit yet. In the meantime, my colleague modify the crontab. * […]

Generate network graph from command line

I recently wrote on gnuplot, today I tried another command line utility to generate graphs, graphviz, version 2.24.0 on AIX5L. Pretty straightforward syntax : (   echo "digraph Emp {"     sqlplus -s -L scott/tiger << EOF       set pages 0 lin 120 hea off feed off       select         ename ||'->'||         (select ename from emp where empno=e.mgr) || ';' […]

What is the current setting of NLS_LANG in sqlplus?

I just learnt a neat trick from Oracle Support. How do you see the current value of NLS_LANG in SQLPLUS ? HOST is not the right answer. E.g.: Unix: SQL> host echo $NLS_LANG AMERICAN_SWITZERLAND Windows: SQL> HOST ECHO %NLS_LANG% %NLS_LANG% The correct setting is revealed by @.[%NLS_LANG%] E.g.: Unix: SQL> @.[$NLS_LANG] SP2-0310: unable to open […]

Time offset in Unix

What is the time offset of the current date in Unix? perl -e '   $t=time;   @l=localtime($t);   @g=gmtime($t);   $d=$l[2]-$g[2]+($l[1]-$g[1])/60;   $gd=$g[3]+$g[4]*31+$g[5]*365;   $ld=$l[3]+$l[4]*31+$l[5]*365;   if($gd<$ld){$d+=24};   if($gd>$ld){$d-=24} print ($d."\n")' 2 Am I in summer (DST)? perl -e 'if((localtime)[8]){print"yes"}else{print "no"}' yes

last access time of a file

I was reading http://blogs.oracle.com/myoraclediary and there was a command about printing the modification details of a file. In Linux / Cygwin “stat” exists as a command $ stat /etc/hosts Access: 2010-08-25 15:20:49.782522200 +0200 Modify: 2010-08-18 14:04:25.868114200 +0200 Change: 2010-08-18 14:04:26.072413100 +0200 Or use the one-liner perl below ### st_atime;         /* Time of last access */ […]

to cvs or to subversion

First surprise, after migration, the size of my subversion folder is double the size of my cvs folder. With a bunch of 2Gb disks shared amoung dozens of unix persons, and regular reminders the current usage reached 100%, you will feel the pain of having each developers doublesizing its home directory… The reason is a […]

extract xml from the command line

I just discovered this morning this cool utility in my /bin directory : xmllint You can use it to extract values from your xml files within your shell scripts $ cat foo.xml <emplist>   <emp no="1">     <ename>John</ename>   </emp>   <emp no="2">     <ename>Jack</ename>   </emp> </emplist> $ echo 'cat //emplist/emp[@no="1"]/ename/text()'|   xmllint –shell foo.xml |   sed -n 3p John I […]

cd

Do you know cd ? I thought I did until this afternoon … OK, let’s start some basic. I create two directories $ echo $SHELL /bin/ksh $ mkdir /tmp/foo $ mkdir /tmp/bar create a symlink /tmp/bar/baz pointing to /tmp/foo $ ln -s /tmp/foo /tmp/bar/baz create a file foo1 in foo $ touch /tmp/foo/foo1 change to […]

cd OLD NEW

Something I like in ksh is to change from /my/old/directory/path to /my/new/directory/path by typing cd old new. This does not work in bash So I had to find a workaround 😉 $ ksh $ cd /app/oracle/product/11.1.0.6/database/rdbms/admin $ cd 6 7 $ pwd /app/oracle/product/11.1.0.7/database/rdbms/admin $ bash $ cd 7 6 bash: cd: 7: No such file […]

return code before grep

In my previous post hide-password-from-ps-output-sql-loader I mentioned a way to pass the password to the loader thru a parameter file. As correctly suggested by Brian Tkatch, the password could be passed as standard input sqlldr control=x.ctl silent=header,feedback <<EOF scott/tiger EOF Username: The Username: prompt is displayed 🙁   🙁 How do we get rid of […]

updatedb does not work with samba drives and cygwin

updatedb and locate are parts of the findutils package, which exists since a long time on most unix / linux flavors. Something I never get worked is to search for files on network drives with Cygwin, I always got : find: /cygdrive/y/Favorites/Links/del changed during execution of find (old inode number -474324984, new inode number -44545478 […]

How to cron?

RTFM is not the best answer … man crontab SunOS 5.10          Last change: 10 Nov 2005 User Commands                                          crontab(1)      A crontab file consists of lines of  six  fields  each.  The      fields  are  separated by spaces or tabs. The first five are      integer patterns that specify the following:      minute (0-59),      hour (0-23),      day of the month (1-31),      […]