Is there a way to capture information logs ( session or workflow ) and grep only ERROR or FAIL messages and send to email distro
using mailx or sendmail option.
I have around 200 sessions running on daily basis and this script has to run every day , and capture only error information .
Thanks
Should be simple, so long as you configure the session to write backwards compatible logfiles then it'll lose all the encoded junk and you can grep for $ERROR or $FAIL
Related
We have one .sh file which contains all the configurations.
We have something like this,
export MARK_REMOTE_NODE= (server name)
The requirement is we have to send the same file to two different servers.Is it possible to transfer the same XFB file to different REMOTE_NODE or servers in UNIX??
When i was searching i got to know that BTOPUT transfers are one file at a time to one Partner.So can anyone tell me how to transfer file to 2 different servers?
XFB already has a hard job matching different operating- and filesystems with optional compression and retry mechanism. You want some logic what will happen when 1 transfer fails (only send second when first succeeds, shoot-and-forget, always try to send both and trust your incident management to catch the errors thrown by your monitoring, wait for async transfer for time depending on filesize,..).
I wouldn't trust the XFB options and just make a loop in your script doing exactly what you want. The additional advantage is that a migration to another communication tool will be easier.
while read -r targethost; do
# You need a copy, since xfb will rename and delete the file
cp outputfile outputfile.${targethost}
my_send_xfb ${targethost} outputfile.${targethost}
# optional check result posting the file in the queue
if [ $? -ne 0 ]; then
echo "Xfb not ready or configured for ${targethost}"
# Perhaps break / send alert / ..
fi
done < myhosts
I run SAS batch jobs on a UNIX server and usually encounter the problem that I cannot overwrite sas datasets in batch that have been created by my user locally without changing the authorization level of each file in Windows. Is it possible to signon using my user id and password when initializing the batch job to enable me to get full authorization (to my own files) in batch?
Another issue is that I don't have authorization to run UNIX commands using PIPE on a local remote session on the server and can hence not terminate my own sessions. It is on the other hand possible to run PIPE in batch, but this only allows me to terminate batch jobs so I also wonder if it is possible to run a pipe command in batch using my id and password as the batch user does not have authorizatio to cancel "local remote sessions" on my user?
Example code for terminating process:
%let processid = 6938710;
%let unixcmd = "kill &processid";
%PUT executing &unixcmd;
filename unixcmd pipe &unixcmd.;
there's a good and complete answer to your first point in the following SAS support page.
You can use the umask Unix command to specify the default file permission policy used for the permanent datasets created during a SAS session (be it batch or not).
If you are lauching a Unix script which invokes a SAS batch session you can put a umask command just before the sas execution.
Otherwise you can adopt a more permanent solution including the umask command in one of the places specified in the above SAS support article.
You are probably interested in something like:
umask 002
This will assign a rw-rw-r-- file permission to all new datasets.
I want to send emails asynchronously for faster and lighter http responses, but I'm struggling with many new concepts.
For example, the documentation talks about spool. It says I should use spool with a file, and then send emails with a command. But how should I be running that command? If I set a cronjob to execute that command every 1 minute (the minimum available in cron), users will have to wait an average of 30 secs for their emails to be sent (eg, the registration email).
So I thought of using a queue instead. I'm already using RabbitMQBundle for image processing (eg, thumbnail creation). But I only use this one periodically, so it is consumed from within a cronjob.
Maybe I should create a daemon that is always waiting for new messages to arrive the email queue and deliver them ASAP?
The solution is to send every email to a queue, and then consume that queue with a service. My service is very simple, it just takes items out of the queue, where each item is an array with from, to, body, etc., and sends that email. I'm using Thumper which makes Rabbit easier to use: github.com/videlalvaro/Thumper . And I make sure the service is always up using 'sv' (from Runit): smarden.org/runit/sv.8.html . You can use any other service or daemon manager you like.
I have the same problem as you had. How you finally solved your problem?
For the moment I run a little script in the crontab in order to run in loop:
<?php
include('/var/www/vendor/symfony/symfony/src/Symfony/Component/Filesystem/LockHandler.php');
use Symfony\Component\Filesystem\LockHandler;
$lock = new LockHandler('mailer:loop');
if ($lock->lock()) {
system('cd /var/www && php app/console swiftmailer:spool:send');
sleep(1);
$lock->release();
shell_exec('cd /var/www && php LoopMailer.php > /dev/null 2>/dev/null &');
}
It's not very clean but it does his job.
You need 2 services one for spooling message and other for send instant emails. Check this
I did ask this question before but that thread was closed as the question was vague. So here is try #2:
I wish to have a simple script that connects to a remote machine via telnet, then executes the command ZAHO, and then stores the output in a file cat.txt on my local machine. Here is the code I tried:
(echo "PPATIL"; sleep 1 ; echo "IDEA#2010" ; sleep 1;) |telnet 10.110.3.132 23<< EOF
ZAHO; > cat.txt
EOF
The following thing happens when I run the script:
Trying 10.110.3.132...
Connected to 10.110.3.132.
Escape character is '^]'
After this, I come back to my shell prompt without anything happening.
Now, even when I supply a wrong a password, I still get the same error.
P.S.: spawn/expect/send are not present and only option to login is through telnet.
I also tried this
(echo "PPATIL"; sleep 1 ; echo "IDEA#2010" ; sleep 1;echo "ZAHO;";) |telnet 10.110.3.132 23
In this case however, the remote machine gets connected, it shows me the username prompt, enters the username, then shows password prompt, then enters password, sleeps for a second and then appends "ZAHO;" to the password, and gets disconnected.
If I remove echo ZAHO; then also it gets disconnected after entering username and password.
In general:
cmd | cmd2 << EOF
EOF
is ill defined. (I'm not sure if the shell grammar clarifies this as undefined, or implementation defined, or what, but it certainly is not going to do what you want.) cmd2 can only have one input source, but you are trying to give it input both from the pipe and the heredoc. You need to pick one. Perhaps you can try:
{ cmd1; cat << EOF; } | cmd2
input
EOF
but that is pretty obfuscated, and you would be better off writing a script to generate the desired input.
If you are not restricted to shell script. Python has a
telnet interface in its standard library. Actually the example given on the library documentation page, is very close to what you want.
Python is perhaps not as ubiquitous as shell, but it is widely deployed and used.
I have a java program, let's say Test.class.
When I execute java Test the program ask for a Password and then continute.
The problem is that the stdout is redirected to a log and the program is launched with the & ( we are on UNIX).
How can i interact with this program launched java Test & with the stdin and stdout?
One possible solution is to start the program in foreground and then after a condition run it in background from java.
Thanks!
If the program can read the password from stdin, you can have a Unix script prompt for the password, then start the Java application and pass the password to it, e.g.:
echo $PASSWORD | java Test >log.out &
Or you can consider to split your Java application in two parts; there could be one interactive "front-end" part that validates the password, and then once the password is validated this could launch a "back-end" part as a background process and exit.
One option is to pipe the input to your program using echos as:
(echo input1
echo input2
....
) | java Test >& logfile &
Alternatively if the number of inputs are large you can also put your inputs in a file and redirect the file contents as:
< input_file java Test >& logfile &
I don't see anything Java specific in this question, if you want to drive the stdin based on the application output, you can use the Expect utility: http://en.wikipedia.org/wiki/Expect
Beware though, Expect is notoriously fragile, you'd do wise to refrain from using it in production scenarios.
Actually if you only want to be able to enter the password, perhaps you can try launching your app in foreground (without the trailing &).
Then, after you have entered the password, press Ctrl+Z or in another shell do kill -SIGSTP <pid> in order to suspend your program. Finally, type bg to put it in background.
Read the docs about your shell's job-control functionality for details.