SCP + sudo

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

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

Published
Categorized as unix Tagged ,

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

Published
Categorized as unix Tagged

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

Published
Categorized as linux, unix Tagged

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

Published
Categorized as unix Tagged

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

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

Published
Categorized as sqlplus, unix

[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

Published
Categorized as news, unix Tagged ,

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

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

Published
Categorized as linux, unix

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

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

Published
Categorized as unix Tagged

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