Sometimes you like to copy files from A to B and you have sudo rights on A and B and you do a lot of “cp” to /tmp and chmod and chown’s. This is annoying… Firstly, I dislike tempfiles. they use space they generate bugs when run in parallel they often are prone to code… Continue reading SCP + sudo
Category: unix
network ip calculation with ifconfig
Most *nix are different. I’ll start with a plain Linux output ifconfig eth0 eth0: flags=4163 mtu 1500 inet 93.184.216.34 netmask 255.255.255.0 broadcast 93.184.216.255 to get the network ip, I just bitwise-and the inet and the netmask. To do it with the shell, I convert the ip to an integer and use the & (AND) operator… Continue reading network ip calculation with ifconfig
on parsing arguments in shell
While most programming languages are accepting arguments as an array of strings, shell doesn’t arglist.c #include int main(int argc, char **argv) { int i; for (i=1; argc>i; i++) printf(“$%d=%s\n”,i,argv[i]); } $ make arglist cc arglist.c -o arglist $ ./arglist one two three four $1=one $2=two $3=three $4=four To do the same in shell, it requires… Continue reading on parsing arguments in shell
on logical and physical working directories
many ignore the difference meaning of .. (dot dot) as an argument when used with ls or cd this leads to buggy coding and wrong parsing of arguments in scripts let’s start with an example $ mkdir $HOME/test $HOME/test/physical $HOME/test/foo $ cd $HOME/test/foo $ ln -s ../physical logical $ cd logical $ ls -l ..… Continue reading on logical and physical working directories
on input and output file descriptors
Let’s start with some basics. The basics works as well on Unix, Linux and Windows. Later techniques only work on linux/unix $ ls -l hosts -rw-r–r–. 1 root root 211 Oct 5 2015 hosts $ ls -l xxx ls: cannot access xxx: No such file or directory $ read x foo $ Outpout and error… Continue reading on input and output file descriptors
Standard date format
Let’s start with Powershell Get-Date -format “o” 2019-03-08T17:41:02.7346332+01:00 The “O” or “o” standard format specifier represents a custom date and time format string using a pattern that preserves time zone information and emits a result string that complies with ISO 8601 docs.microsoft.com Now Linux date “+%Y%m%dT%H:%M:%S.%3N%z” In SQL to_char(current_timestamp, ‘YYYYMMDD”T”HH24:MI:SS.FF3TZH:TZM’) for my XML fans extractvalue(xmlelement(t,… Continue reading Standard date format
Unix ODBC Sybase
very similar to Unix ODBC Oracle instead of tnsnames, the connections are defined in $SYBASE/interfaces. the odbc.ini must exists as well in $SYBASE. if you test with unixODBC-devel, keep in mind to use /usr/bin/isql and not $SYBASE_OCS/bin/isql $ODBCSYSINI/odbc.ini [syb] Driver = Sybase16 DSN = syb ServerName=SYB01 $ODBCINI/odbcinst.ini [Sybase16] Description = Adaptive Server Enterprise Driver =… Continue reading Unix ODBC Sybase
Unix ODBC Oracle
To connect via ODBC, check https://laurentschneider.com/wordpress/tag/odbc This article is related to Unix/Linux. Often you have a fat client written in C, while java uses JDBC instead of ODBC. Okay, it’s pretty easy, if you have an oracle client, you probably already have libsqora.so.xx.1 in your LD_LIBRARY_PATH. In this case you can connect using ODBC. What… Continue reading Unix ODBC Oracle
disallow pseudo terminal in ssh
Some Oracle documentation wants you to setup ssh with no password and no passphrase. Configuring ssh This is not really something your security admin will like. First, using DSA, which is deprecated and disabled by default in OpenSSH 7.0, is a pretty dump instruction OpenSSH 7.0 and greater similarly disable the ssh-dss (DSA) public key… Continue reading disallow pseudo terminal in ssh
Don’t call it test
There are quite a few names to avoid in your scripts. Even if there are not reserved-words, keep away ! I’ll start with test cd $HOME/bin vi test echo hello world chmod +x test ./test hello world The problem is that it may break your other scripts $ ssh localhost test 1 = 2 &&… Continue reading Don’t call it test
Untrusted X11 forwarding
I wrote a while ago about my security concerns regarding xhost + xterm -display mypc:0 Way back then, I suggested ssh tunnel. SSH is pretty easy to set up, by enabling the X11Forwarding option. In OpenSSH 3.8 release note, 2004, there was a new default . ssh(1) now uses untrusted cookies for X11-Forwarding In the… Continue reading Untrusted X11 forwarding
run sudo, ssh, password, su in simulated interactive mode
Some commands do not like non-interactive mode $ passwd 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 for lsc: sudo: sorry,… Continue reading run sudo, ssh, password, su in simulated interactive mode
How to *really* send a script to the background
Let’s check this small script – foo.sh #!/bin/sh echo foo.1:`date` | tee $HOME/tmp/foo.txt sleep 3 echo foo.2:`date` | tee -a $HOME/tmp/foo.txt $ $HOME/tmp/foo.sh foo.1:Thu Nov 27 17:34:53 CET 2014 foo.2:Thu Nov 27 17:34:56 CET 2014 Very obvious, I write to the console, wait three seconds, then write to the console. Ok, let’s take another script… Continue reading How to *really* send a script to the background
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… Continue reading fun with cron
Testing for (non-)empty string in shell
One way to test for (non-)empty string is to use test and -z (-n) $ x=foo $ test -z “$x” $ echo $? 1 This is mostly seen with an if and [ -z … ] syntax $ y=bar $ if [ -n “$y” ]; then echo non-empty; fi non-empty Instead of a variable, it… Continue reading Testing for (non-)empty string in shell
hot to bypass requiretty in sudo
You can execute it a command without password from the commande line $ sudo -l User lsc may run the following commands on this host: (root) NOPASSWD: /usr/local/bin/helloworld $ sudo /usr/local/bin/helloworld Hello World! Now you try to run it via cron and you get sudo: sorry, you must have a tty to run sudo The… Continue reading hot to bypass requiretty in sudo
use cron to schedule a job only once
I wrote about not using DAY OF MONTH and DAY OF WEEK simultanously in how to cron The correct method is to use 15 14 15 05 * /tmp/run-my-job But… I wrote this five years ago. Hmmm ! Not that correct then since it would run every year 😉 Ok, periodically I check for jobs… Continue reading use cron to schedule a job only once
return code and sqlplus
Calling a shell script from within sqlplus is buggy… I have reported bug 3798918 in 10.1.0.2 (back in 2004) and bug 13349119 in 11.2.0.3 because some metalink guru closed 3798918 as not reproducible. As written in return code, host does not return the correct code SQL> host exit 7 SQL> def _RC DEFINE _RC =… Continue reading return code and sqlplus
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… Continue reading How to quit crontab -e without overwritting cron
xhost+ security hole part 2
Five years ago I wrote xhost+ is a huge security hole, I turned out red this morning when my neighbour sent me a smiley via X. Do I really want everyone to have full access to my screen? No, I don’t. And I don’t do xhost+. So why did it happen to me ??? I… Continue reading xhost+ security hole part 2
[alert] AIX Posix Timezone issue
Maybe you did get or you will get an issue with the date command in AIX. expected behavior, Linux $ TZ=NZST-12NZDT,M10.1.0/2,M3.3.0/3 date Sat Mar 17 00:14:54 NZDT 2012 $ TZ=Pacific/Auckland date Sat Mar 17 00:14:58 NZDT 2012 unexpected behavior, AIX $ TZ=Pacific/Auckland date Sat Mar 17 00:15:50 GMT+13:00 2012 $ TZ=NZST-12NZDT,M10.1.0/2,M3.3.0/3 date Fri Mar 16… Continue reading [alert] AIX Posix Timezone issue
delete unused shared memory segments from an Oracle instance
Once upon a time, a dba issues some kill -9 to clean up dying database processes. Or the database instance crashes. This will left some shared memory segments. Note 68281.1 describe how to remove them on a server with multiple databases. First, list the ipc process $ ipcs IPC status from /dev/mem as of Mon… Continue reading delete unused shared memory segments from an Oracle instance
Check if it a program is already running in Unix
There is more than one way to do it, the safe is probably to check if /home/lsc/OH_YES_I_AM_RUNNING exists and believe it. This is called the file.PID method and is widely used (Apache used to use it since a long long time). It needs file. It needs cleanup if you reboot your server in the middle… Continue reading Check if it a program is already running in Unix
shell and list of files
How do you loop thru a list of files? For instance you want to archive than delete all pdf documents in the current directory : Bad practice : tar cvf f.tar *.pdf rm *.pdf There are multiple issue with the command above 1) new files could come during the tar, so the rm will delete… Continue reading shell and list of files
pstree in AIX
For those who do not want to download some linuxlike freeware on your aix box, use ps -T 🙂 ps -fT 2412672 UID PID PPID C STIME TTY TIME CMD oracle 2412672 1 0 Sep 05 – 0:00 /u01/app/oracle/product/OAS oracle 630956 2412672 0 Sep 05 – 6:11 \–/u01/app/oracle/prod oracle 1347672 630956 0 Sep 05 -… Continue reading pstree in AIX
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
send graph per mail from sqlplus
How to send a graph with a single command from your database to your mail in Unix? I tried this (gnuplot is available for Solaris, AIX and most Unix derivates) : echo ‘ set hea off pages 0 feed off prom set title “salaries of EMP” prom unset key prom unset xtics prom unset xlabel… Continue reading send graph per mail from sqlplus
vi large files
Once upon a time a colleague asked me if there is a better editor than vi installed on my db server. Well, I was not really about arguing the benefit of ed (less memory usage, no useless error message). But one advantage of ed was (I believed) the ability to read large files $ vi… Continue reading vi large files
scp tuning
I twitted yesterday : laurentsch copying 1TB over ssh sucks. How do you fastcopy in Unix without installing Software and without root privilege? I got plenty of expert answers. I have not gone to far in recompile ssh and I did not try plain ftp. Ok, let’s try first to transfer 10 files of 100M… Continue reading scp tuning
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… Continue reading What is the current setting of NLS_LANG in sqlplus?
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} print ($d.”\n”)’ 2 Am I in summer (DST)? perl -e ‘if((localtime)[8]){print”yes”}else{print “no”}’ yes