473,382 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Why does my ksh shell script die unexpectedly?

112 100+
I have a shell script that ssh over to another box, runs a cattail command on a log file, and redirects the output over a file on a different directory on the local box.
The name of the shell script is: desktop_SHM.ksh
Expand|Select|Wrap|Line Numbers
  1. #!/bin/ksh
  2.  
  3. ssh infrap@ics0001 '/sbt/prod/infra/bin/cattail /sbt/prod/infra/v2run_dir/log/alarmNotification.log' > /infra/sbt-support/supportTools/hsqldb/ics/tmp/alarmNo
  4. tification.log.orig
  5.  
I have this shell script running as a cronjob at 7:30am, monday to friday, but for some reason, when i come in at 8:00am and check to see if it is running, it has died at 7:30am after running once.
Expand|Select|Wrap|Line Numbers
  1. 30 7 * * 1-5 /infra/sbt-support/supportTools/transferOutliers/bin/desktop_SHM.ksh > /dev/null 2>/infra/sbt-support/supportTools/logs/desktop_SHM.err
  2.  
The desktop_SHM.err file is blank.

If I run this script from the command prompt, it works fine all day till I manually kill it, however if I run this script from the command prompt, but in the background, when i change directories it stops also.
Expand|Select|Wrap|Line Numbers
  1. [7]+  Stopped                 desktop_SHM.ksh
  2.  
I am unsure why this is happening if someone can please help me.
Aug 19 '11 #1
13 2951
sicarie
4,677 Expert Mod 4TB
You're SSH'ing from local box A into a remote box B to redirect a file to a different location in remote box B?

Why not just set a cron on box B to copy the file every 5 minutes?

If it's redirecting that output back to box A, why not just send it over by utilizing syslog on box B and a collector on A? That would be close to live and not dependent on cron...
Aug 23 '11 #2
ndedhia1
112 100+
That is basically correct.
If i run the script in the background, it works fine also as long as I dont change directories or run too many other commands on the command prompt. It seems as though even if i am running it in the background, I have to leave that session alone.

Running the script in the terminal manually definitely works fine alllll day long.

There is nothing of interest in the /var/log directory.
I believe the script exits after cattailing over the correct data 1 time. I think after the cronjob runs my script, it runs once, and then dies because whatever is running the crobjob, either dies or starts some other job, and my script dies because I feel as though its very dependent on the session that runs it. I am not sure if i am explaining this right, but if you have any more questions, please let me know.

thanks for the help!!
Aug 23 '11 #3
sicarie
4,677 Expert Mod 4TB
Sorry, I wasn't paying attention to the way the solution was architected originally and revised my response. Any thoughts to the solutions presented? Or was this assigned and needs to be a modification of what is there right now?
Aug 23 '11 #4
ndedhia1
112 100+
I need the data in the logs completely real-time. I thought about that solution, but even having it copy over every 1 min is too long of a lag time.
I believe this can be done the way that i am doing it manually, but I am not understanding why it is dying as a cronjob or dying periodically as a job that is run in the background.
Aug 23 '11 #5
sicarie
4,677 Expert Mod 4TB
Have you looked into syslog? It seems that sending the individual event as soon as it comes across would be less intensive than ensuring an ssh'ing cronjob was active.
Aug 23 '11 #6
ndedhia1
112 100+
i havent looked into that and definitely will. Thanks!
Aug 23 '11 #7
ndedhia1
112 100+
the file that i am collecting data from is actually running syslog to capture its content. I need the captured contents also for an app that I am running.
Can I run syslog on a file and can you give me examples of how this works.

thanks
Aug 23 '11 #8
ndedhia1
112 100+
is there anything you see in the shell script or the way I am running the cronjob that I am doing wrong?
Is there a ssh switch that I am missing or something that would allow for this to work?
Aug 23 '11 #9
ndedhia1
112 100+
A lot of other threads that I have read, in which people are having this same problem, are saying that this is an environmental issue. Is this something I could be doing wrong, because I am not really using any variables?
I added these two lines to my shell script just to make sure that the file I am writing to has read/write access.
I am creating an empty file called alarmNotification.log.orig and then giving it 777 permission
Expand|Select|Wrap|Line Numbers
  1. >/infra/sbt-support/supportTools/hsqldb/ics/tmp/alarmNotification.log.orig
  2. chmod 777 /infra/sbt-support/supportTools/hsqldb/ics/tmp/alarmNotification.log.orig
  3.  
do you think that this could be the issue?
I wont be able to test it till tomorrow morning when the cronjob runs again.
Aug 23 '11 #10
sicarie
4,677 Expert Mod 4TB
By 'environmental' I beleive they're saying the entire environment from your computer to server to switch to other server, etc... not just the environment variables in a shell script.

I really believe syslog would accomplish what you'd like to do, but it does take a bit to configure. You obviously have SSH keys set up, so I'd recommend putting the cron to every minute (or something reasonable, and check the behavior. Then try setting under 1 minute and look at the behavior.

Another option, outside syslog, is to set some sort of network share or mapped hard drive on both that you could mount locally on your computer. Then it would look like it was both logging locally and reading the file locally. That depends on what your'e doing though, especially if there are a lot of reads going across the network, or if you were manipulating the data.

I'd still recommend looking in /etc/syslog.conf to try to mimic the behavior (though yours right now isn't turned on, it'll give an outline of what it looks like), and then try to figure out how to set a listener up on your computer. One of the most popular and more up to date versions of syslog is called syslog-ng.
Aug 24 '11 #11
ndedhia1
112 100+
Unfortunately,
I am not the network admin where I can configure many things on this box to allow syslog to work and also can not create a shared or mapped hard drive on both boxes.

I had this working in the past using Rexec, but last week, Rexec was disabled on the destination server so this no longer worked for me giving me a Connection refused error:
Expand|Select|Wrap|Line Numbers
  1. $ desktop_SHM.ksh.081611
  2. server =ics0001,userName=infrap,password=infrap,cmd=/sbt/prod/infra/bin/cattail /sbt/prod/infra/v2run_dir/log/alarmNotification.log
  3.  
  4. java.net.ConnectException: Connection refused
  5.         at java.net.PlainSocketImpl.socketConnect(Native Method)
  6.         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
  7.         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
  8.         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
  9.         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:367)
  10.         at java.net.Socket.connect(Socket.java:529)
  11.         at java.net.Socket.connect(Socket.java:477)
  12.         at java.net.Socket.<init>(Socket.java:374)
  13.         at java.net.Socket.<init>(Socket.java:187)
  14.         at com.cboe.utility.RexecClient.<init>(RexecClient.java:76)
  15.         at com.cboe.utility.RexecClient.<init>(RexecClient.java:17)
  16.         at com.cboe.util.outlierMonitor.TransferOutliers.getOutliers(TransferOutliers.java:62)
  17.         at com.cboe.util.outlierMonitor.TransferOutliers.main(TransferOutliers.java:168)
  18.  
this is the shell script that was working for me up until last week:
Expand|Select|Wrap|Line Numbers
  1. #
  2.  
  3. java -DUniqueID=desktop_SHM \
  4.      -DSERVER=ics0001 \
  5.      -DREMOTEDIR=/sbt/prod/infra/v2run_dir/log/ \
  6.      -DREMOTEFILE=alarmNotification.log \
  7.      -DLOCALFILE=/infra/sbt-support/supportTools/hsqldb/ics/tmp/alarmNotification.log.orig \
  8.      -DREMOTECOMMAND=/sbt/prod/infra/bin/cattail \
  9.      -DUSERNAME=userID \
  10.      -DPASSWORD=userPass \
  11.      -classpath /infra/sbt-support/supportTools/transferOutliers/classes/Rexec.jar:/infra/sbt-support/supportTools/transferOutliers/classes/Utility.jar com.c
  12. boe.util.outlierMonitor.TransferOutliers \
  13.  
Aug 24 '11 #12
sicarie
4,677 Expert Mod 4TB
Well, now you're getting into circumventing what someone else put in place, so I'm going to have to recommend you get whoever disabled that, your network admin, and your boss in a room to discuss your options (such as re-enabling, syslog, mapped network drive, or another idea).

It sounds like what you're doing is being blocked by your network/host admins, and I can't help you get around what they're putting in place as it violates the terms of use of this site.

Sorry and good luck!
Aug 24 '11 #13
ndedhia1
112 100+
i dont want to get around what my network admins blocked. They wrote to me in an email that Rexec is being disabled and that i need to make this work using SSH.
I get what I need to do to work using SSH if i run the shell script via command line, but when i try to run it as a shell script, it dies after the first run. The file that is being appended to, alarmNotification.log.orig is updated up to 7:30am, which is when the cronjob is supposed to kick off. After that, it is never updated, which tells me that the cronjob died.
When i run it via command line, that file is updated all day long, every time a new log file appears in the alarmNotification.log file on the remote server.
Aug 24 '11 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Juggler | last post by:
Hi, I have a shell script which takes three arguments, how can I call this script from within a C++ program. I am new to C++ programming and not sure how to accomplish this. I tried using...
3
by: FPGA05 | last post by:
Hello All, I am developing a small application in which I would need a C++ application to read the output from a shell script. A shell script keeps looking for user inputs and once the user...
1
by: news | last post by:
At the end of a PHP script, I'm sending a file via FTP to a server. I thought it'd be best to use a shell script in order to automate the FTP (logging in, changing to binary, putting the file,...
2
by: jonathan184 | last post by:
Hi I am trying to create a shell script that will look for a contracthead file first and if the contract head file does not exist on day1 exit script. Now on day2 if contracthead exists or...
3
by: telduivel | last post by:
Can someone please help me with this: I have a python script, that at some point calls a linux bash script (.sh). Starting the shell script is the last thing my python script needs to do, so I...
2
by: ellennolan | last post by:
Hello, I wonder if anyone can help with calling external shell script in c++. Basically, in the shellscript, I want to pass src, dst, md5. If the src's md5 matches md5 given, it will be link to...
1
by: jrw133 | last post by:
So im working on a lab for my unix class and im having some problems with this shell script we are supposed to do here is the question: Write a shell script that accepts a list of files(space...
5
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
4
by: devi thapa | last post by:
Hi, I am executing a python script in a shell script. The python script actually returns a value. So, can I get the return value in a shell script? If yes, then help me out. Regards, Devi
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.