Explain plan statement in DB2 not working using shell script - unix

I have used the below statement in my script to get the explain plan for a stored procedure but its throwing error
a=`db2 -x "SELECT current timestamp FROM sysibm.sysdummy1"`
c=`echo $a|cut -d"." -f1-2`
time_new="'$c%'"
db2exfmt -d ${DATABASE} -e ${DATABASE} -g -l -n -s ${SCHEMA_NAME} -o SP_explain_plan_${TIMESTAMP}.out -w ${time_new} -# 0 -v %
Its not able to read the timestamp correctly. Can someone help

Related

Salt-stack target minion with argument and script

Start of script looks like this:
salt-key -L >/path/minions
SERVER=`shuf -n 1 /path/minions`
salt -C $SERVER file.write /tmp/salt_eicar.sh args='X5O!P%#
and so on...
This works fine. No problem.
This does not work:
salt -C '$SERVER and not G#os:Windows' file.write /tmp/salt_eicar.sh args='X5O!P%....
But above line works fine in prompt with a minion name instead of $SERVER. So something with a variable inside -C I suppose?
It's a shell issue. You should use double quotes " to allow bash to expand the variable $SERVER.
salt -C "$SERVER and not G#os:Windows" file.write /tmp/salt_eicar.sh args='X5O!P%....

ldapadd does not restore complete backup

I have replication set up with 2 producers and a consumer.
I take a backup using below command:
ldapsearch -c -H ldapi:/// -D "cn=admin,dc=comp,dc=com" \
-y "/run/secrets/pwd" -b "dc=comp,dc=com" -LLL > openldap-data-backup.ldif
Let's say I want to restore this backup using ldapadd with "-c" to ignore the already present entries:
ldapadd -H ldapi:/// -D "cn=admin,dc=comp,dc=com" -c -y /run/secrets/pwd -f openldap-data-backup.ldif
All the entries that already exists are ignored (which I believe is because of -c option). But the attributes like userPassword stays as per value before the restore. The restore using ldapadd does not change userPassword at all.
is this behaviour expected?
ldapsearch will not output all attributes by default, so your passwordhash is probably not even exported with your command. Did you check your openldap-data-backup.ldif for password hashes?
# untested
ldapsearch -c -H ldapi:/// -D "cn=admin,dc=comp,dc=com" -y "/run/secrets/pwd" -b "dc=comp,dc=com" -LLL "(objectclass=*)"
# or
ldapsearch -c -H ldapi:/// -D "cn=admin,dc=comp,dc=com" -y "/run/secrets/pwd" -b "dc=comp,dc=com" -LLL "(objectclass=*,+)"
you can use slapcat/slapadd without downtime to my experience. Before syncprov we used this to 'sync' our master and slaves.
also this answer

Clozure CL compiled executable losing certain command line arguments

I'm writing a utility program in Common Lisp and building it with Clozure CL; I would like to be able to use the command-line option -d with the program, but for some reason this particular option won't make it through to (ccl::command-line-arguments). Here is a minimal example:
(defun main ()
(format t "~s~%" (ccl::command-line-arguments))
(quit))
I compiled with
(save-application "opts"
:toplevel-function 'main
:prepend-kernel t)
and here's some sample output:
~/dev/scratch$ ./opts -c -a -e
("./opts" "-c" "-a" "-e")
~/dev/scratch$ ./opts -c -d -e
("./opts" "-c" "-e")
~/dev/scratch$ ./opts -b --frogs -c -d -e -f -g -h --eye --jay -k -l
("./opts" "--frogs" "-c" "-e" "-f" "-g" "-h" "--eye" "--jay" "-k" "-l")
The -b and -d options appear to be getting lost. The documentation on command line arguments for ccl isn't very helpful. I thought maybe because ccl itself takes -b as an argument, that option might have gotten eaten for some reason, but it doesn't take -d (which is eaten), and it does take -e and -l which aren't. Nothing on saving applications seemed helpful.
I'm pretty sure it's Clozure-specific (and not, say, the shell eating them), because other stuff seems to be getting all the arguments:
#!/usr/bin/python
import sys
print sys.argv
yields
~/dev/scratch$ ./opts.py -a -b -c -d -e
['./opts.py', '-a', '-b', '-c', '-d', '-e']
and
#!/bin/bash
echo "$#"
gives
~/dev/scratch$ ./opts.sh -a -b -c -d -e
-a -b -c -d -e
This is all taking place on lubuntu 15.10 with bash as the shell.
If anyone could shed some light on why this is happening or how I can end up with all my command-line switches, I'd be appreciative.
Thanks.
According to the source code of the 1.11 release, -b and -d are options used by the lisp kernel.
Since I'm unsure about licence issues, I just provide the link to the relevant file: http://svn.clozure.com/publicsvn/openmcl/release/1.11/source/lisp-kernel/pmcl-kernel.c
Command line arguments are processed in the function process_options, where for options -b (--batch) and -d (--debug) - among others - a variable num_elide is set to 1. A bit further down, this leads to overwriting the option with the following argument (argv[k] = argv[j];).
The code also shows a possible fix: Supply -- (two dashes) once as argument before -b or -d. When above function encounters a -- it stops processing the rest of the arguments, thus leaving them unchanged to be possibly taken up into "lisp world" shortly after.
Turns out this has already been solved at SO before:
https://stackoverflow.com/a/5522169/1116364

mutt command with multiple attachments in single mail unix

My requirement is to attach all the .csv files in a folder and send them in a single mail.
Here is what have tried,
mutt -s "subject" -a *.csv -- abc#gmail.com < subject.txt
The above command is not working (It's not recognizing multiple files) and throwing the error
Error sending message, child exited 67 (User unknown.).
Could not send the message.
Then I tried using multiple -a option as follows,
mutt -s "subject" -a aaa.csv -a bbb.csv -- abc#gmail.com < subject.txt
This works as expected.
But this is not feasible for 100 files for example. I should be able use it with file mask (as like *.csv to take all csv files). Is there is any way we can use like *.csv in single command?
Thanks
Mutt doesn't support such syntax, but it doesn't mean it's impossible. You just have to build the mutt command.
mutt -s "subject" $( printf -- '-a %q ' *.csv ) ...
The command in $( ... ) produces something like this:
-a aaa.csv -a bbb.csv -a ...
Here is the example of sending multiple files using a single command -
mutt -s "Subject" -i "Mail_body text" email_id#abc.com -c email_cc_id#abc.com -a attachment1.pdf -a attachment2.pdf
At the end of the command line use -a for the attachment .
Some linux system have attachment size limit . Mostly it support less size .
I'm getting backslash( \ ) Additionally
Daily_Batch_Status{20131003}.PDF
Daily_System_Monitoring{20131003}.PDF
printf -- '-a %q ' *.PDF
-a Daily_Batch_Status \ {20131003 \ }.PDF -a Daily_System_Monitoring \ {20131003 \ }.PDF
#!/bin/bash
from="me#address.com"
to="target#address.com"
subject="pdfs $(date +%B) $(date +%Y)"
body="You can find the pdfs from $(date +%B) $(date +%Y)"
# here comes the attachments
mutt -s "$subject" $( printf -- ' -a %q' $PWD/*.pdf ) -- $to <<EOF
Dear Mr and Ms,
$(echo $body)
$(cat ~/.signature)
EOF
but it does not work with escape characters in file name like "\[5\]" which can come in MacOs.
I created as a script and collect needed PDFs in a folder and just run the script from that location. So monthly reports are sent... it does not matter how many pdfs (number can vary) but also there should be no white space.

Problem with plink output

I'm using plink to run a command on a Unix remote machine.
The command is:
ls -1trd testegrep.txt |tail -1 |xargs tail -f| grep 's';
The way I'm sending this command is by using a file with a set of commands like:
plink.exe -ssh -t -l user -pw pwd tst.url.pt -m commands.out
When I run the command this way the plink does not receive any input. It seems that is waiting for input.
But if I run:
plink.exe -ssh -t -l user -pw pwd tst.url.pt "ls -1trd testegrep.txt |tail -1 |xargs tail -f| grep 's';"
I get the expected result.
I'm not using the plink with a file with the command because I choose so. I'm using a test automation software that allows me to run tests on remote hosts and this is the way the tool works.
Any thoughts on what is going wrong?
I tested the command you provided and it worked without problems.
Maybe the problem is related to:
The server's host key is not cached in the registry.
The path to the file is not correct.
The file is empty.
include server hostkey
most importantly, you need to include the unix profile using the -m paramater
You can include all your commands in the same file where the profile is kept also.
$Output = ((plink.exe -hostkey hostkey -l UNAME -i SSHKEY -P 22 -ssh server -batch -m PROFILE) | ? {$_ -ne ""})

Resources