Programming :: Loading Environment Into Bash Script Called By Cron?
Mar 18, 2010
Script programming question for the experts. I have written a bash script that works fine if I execute from the shell interactively. However, once I schedule it to be executed via cron, it just wouldn't work. I believe this has to do with cron running in a different environment than the one I am in when I putty in.
The bash shell script does refer to environment variables in the .cshrc file. I guess these aren't available to the cron? How can I load them into the script if I want them to be available to the cron locally within the script?
I have an rsync script I wrote that I have tested and it works perfectly when I run it manually. Now I am working on a server setup script and I have gotten my setup script to create the rsync script in /etc/cron.hourly and restart crond. To spite the fact that the script is in /etc/cron.hourly and I have restarted crond, the script does not run. With that said, how can I script adding the rsync script to run hourly as a cron job?
I feel there's a bit of a misunderstanding going on between C++ and me...My problem is that I have a deque of pointers to a class, and create objects then add them to the deque in a for loop. However, the destructor is called on the object as soon as the loop quits.
Code:
This prints:
Code:
Now, if I change the deque from deque<Test*> to deque<Test> then it works fine - I get:
Code:
However, I can't do this with my actual code, because I am creating a deque of pointers to an abstract class, so it won't let me instantiate the class. (This is all so that I can take advantage of polymorphism, and call functions on a set of similar objects without worrying what type of object I'm dealing with).
So, I suppose my question is: what is the correct way to create that deque of pointers to the abstract class? I don't seem to be barking up the right tree currently.
I have a script that that is supposed to send me an e-mail when a host is not responding to ping:
The script works fine when I execute it directly but when cron executes it, the ping error is never picked up by the script so the if statement is ignored.
I've made a bash script to do scp a file from another server and tested it successfully by executing it manually. However, when I scheduled it by cron, I received a mail from root saying permission denied.
The script is at:
It's supposed to secure copy a file from a remote host to:
The script's content is (No need to supply password as I've done the ssh-keygen thing):
Code:
From what I can make out of the mail, it appears that it has problem saving it to the /home/backup directory.
1. What is it called when you move a PDF window while it is loading and the window manager does not keep up with the image, (it gets all blurry when the window is moved?)Why does this happen?
2. Why is it that when a browser window is clicked to load a new address it won't always go to it. It has to be clicked again.
3 Why is it that sometimes IE is the only browser that will work on XP. FireFox and Opera will not load a page but IE will.
4 Why is it that Firefox on Linux sometimes everything inside the window is slow to appear. It has to be closed to fix it. When the contents does appear it is all at once.
5.Why is printing different things on Linux a problem. I have a lot of inconsistency with trying to print things from Evince. Some docs print and some won't. Copying and pasting is also a problem for Evince.Why?
6. Is there a way to have Linux Shut down after computer activity has stopped and not just with a timer. Lets say I'm trying to download something and I want it to turn off after it has finished with the down load.
7. Why are some Web pages biased towards Windows. I notice that some java scripts will only run right on Windows machines with IE. A lot of on-line forms are like this.
8. Can (MOVIES, PICTURES AND MUSIC) torrents be downloaded on Linux without risk?
9. It seams that Linux browsers do not keep previous web pages in memory so if you want to go back Linux always has to reload them from the server. Why is this?
10. Why is it that browsers sometimes won't indicate that the page has finished loading, "ever".
11. Why does Linux turn on the number-lock when loading its self?
12. Why can't the brightness be adjusted in Totem? There is a menu to change it but it does not work.
My execution environment is Linux steamboy 2.6.31-21-generic-pae #59-Ubuntu SMP.If I log in and run a program, the program works properly. The program is a shell script, which executes an environment file, so that path and library settings point correctly.If I have cron run the same program as the same user who logged in, one of the libraries cannot be found. I have sourced .bashrc and the same environment setting file, even though .bashrc executes the same environment file . /home/amr/bin/informix_env.sh
I'm planning on writing a BASH script for my website's server that will process data from user input via HTML forms, and then write data to the website's HTML documents. My question regards how to deal with the possibility that two users send form information very close to the same time, thus having the BASH script being called again while the first instance of the script has not yet finished.
I don't even know what happens in general when a BASH script is called while it is still running. Even if that is ok, and a new, separate script process is started (or whatever really happens), how am I supposed to prevent issues that could come from two different instances of the script trying to write to the same file at the same time? Is there a way to force the BASH script to finish its work before launching again, in the event of multiple requests?
In programming sense what is Desktop ?I can run any gnome apps using terminal or "Run Application" ?Such as , to open terminal i can type gnome-terminal and it invokes. What is Xwindow , xserver and Why do we need Gnome , KDE etc ?Why i cannot launch any graphical application [ firefox as example ] without loading xserver ?? I donot need wallpaper , start menu bla bla .. I only want to run any graphical applictaion using default black terminal.
I've got a bash script that uses rsync via SSH to back up data from a remote webserver. This script works fine when I run it myself but when it runs as a cron job I get the following error:
I have a script that pops up a jpg file several times a day as a reminder. The script is called up by crontab and it works perfectly.The issue is that I want the script to also perform a system "beep" in addition to popping up the jpg file. When I test it on the command line everything works but when I run it in cron the jpg file pops up but the beep doesn't beep. I'm thinking the problem is in the "echo -e \a" part. I must be missing something.Here is my script:
Code: #!/bin/sh chown -Rc steven:users "/home/steven" I have more lines in the script but each line does the same error. This is run in a cron job but it always returns.
Code: chown: cannot access `/home/steven ': No such file or directory But it is a valid directory I have even tried adding an / and even a space on the end and still same error.
I have a personal server and a dynamic IP address, so I wrote a script to check the currently assigned IP address and compare it to the one stored in a file from the last check, and visit the update URL if it's different.
I'm really running into a wall trying to figure this out. I have a Bash script and narrowed down the one command that doesn't seem to work via cron and it's my pgp decrypting line. Works fine if I run the command via terminal but if I run it via cron it doesn't output anything.crontab -e shows the cronjob and it runs, creates the log file with no output. Is there maybe something I need to run as well? Permissions look set, unless the cron is running as a different user(was under the assumption if it showed up under crontab while logged into that user, then it would run as that user.
I have script which does file locking via flock and then writing it's pid into that file. It perfectly works being run by hand in terminal, running under cron on Debian, but somehow fails being run under cron on Centos 5.6. Script part and straced outputs are below.
I have our own C written program code which is communicating with a third party C++ written program code to run a moving device. We have successfully communicated with the third party code with wrapper functions. (Thanks to member in LQ that helped me solved this.)Now, we tried to run some functions to move the device. I think it is better for me to attach the related code first. pro.c (The source code we used to run the device)
x is a variable which is taken from a very beg text file > 64MB
first line of my code is cout<<" Wait Running...";
my code takes text file as an input, takes its data and generates an output text file....
Code is running fine for small data tried till x= 10
but while trying to run with large data ie x = 5000000 approx it is giving error Even the first line of the code is not displayed. NOTE: variable is declared global but its size is defined in main.
The error that i am getting after approx 2-3 minutes is:
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Wait Running...Aborted (core dumped)
What is the Terminology called of a Binary using a file that is not part of it's self? An example would be when a browser uses a HTML file for it's interface. The binaries code has to know how to find it and so on. I imagine that the applications binary uses a system call and that another application takes over.
I suspect this will be beyond my abilities but thought I'd give it a try. A few months ago I wrote code for an application called nagios which would send me tweets when a system within my network ran into a problem (code below):
I thought about this a while ago when reading through a Python tutorial and I googled some and couldn't find an answer. Now I want to know it for Ruby, also, and it's more important now because I want to invoke Ruby with -w.
How can you use:
Code:
with a -w option to ruby, like:
Code:
This doesn't work and I can't find an explanation of how to do it.
I'm trying to get cron to run a bash script every 15 minutes to change my desktop background
running crontab -e I added
Code:
*/15 * * * * sh /home/ME/Documents/scripts/background.sh
(at first i didnt have the sh before the path of the script but read somewhere i needed that) But it doesnt seem to be running my script works fine if ran straight from the terminal so Dont think thats the problem.
How can I move around the bash commandline efficiently?In the Windows prompt, one can go back or forward one word by pressing ctrl and <-/->.What's the equivalent in a bash environment?
I am using Linux some years, but since I built a LFS, I feel noobish again. Now with the help of BLFS I am setting up my environment and somewhere I incidentally read, that not every variable is inherited by a child Bash shell. As for the $PS1 and $PS2 variables I know, that they are not inherited by non-interactive Bash shells (and there is no reason why they should in my opinion). Well, as for my first thread I hope the title gives enough information on what I want to know. But anyways: Which environment variables are not inherited by Bash shells?