I hope I can explain my problem clearly.
I have a Perl script that I run from the command line like this
perl update_blastdb.pl databaseName --passive
As you see, I must add parameters in the command line.
I want to automate the running of this script weekly with an parameter.
The task manager in Windows can schedule a task to run automatically, but I think if I give the Perl file path to the task scheduler, it will be run without any parameters.
What is the best way to do what I want? I thought of creating a new Perl file that has:
Arguments in variables fields
A command variable that sends the parameter with update_blastdb.pl to the command prompt.
But I am just thinking and I don't know whether this is possible.
Can anyone help me find the right direction please?
I would have thought it was as simple as this
at 05:00 /every:M,T,W,Th,F cmd /c perl update_blastdb.pl databaseName --passive
The only problem might be that the current directory isn't what you expect. Scheduled tasks run under the System account with their current directory set to SYSTEMROOT, which is generally C:\Windows
Related
I am trying using ruby script to a task.
I have an .exe file that i want to run.
when opening this file it open in CMD and i can pass commands to it.
That file located in C:\temp\test.exe
I need to go to the directory and then open the file and then insert to it command like:
"getobject" task = "aa"
this program will give me the result to the CMD.
i will need to copy the result to text but i think i can handle it late.
I tried to search it online cant found anything.
Thanks
If you want to open an executable, usually you can use the `command` syntax in Ruby. So call:
`C:\temp\test.exe`
That should run the executable from the Ruby script. Then you can interact with that executable as if you ran it from a CMD instead of a Ruby file.
In order to run and capture the output of a command you'll need to use a system command. There are many system commands that you can use, but my preference is Open3:
require 'open3'
output, status = Open3.capture2("C:\temp\test.exe")
In the event that you want to pass command line arguments to capture2 you'll want to write that like this: Open3.capture2("C:\temp\test.exe", "arg1", "arg2"). That is the safest way to pass arguments.
I think what you are looking for is input/ output redirection
check redirection
Not tested
system 'C:\temp\test.exe < "\"getobject\" task = \"aa\""'
I am trying to convert a shell script to a batch file line by line and command by command. However, I cannot seem to get around the following line. Any help appreciated.
OPTS="%OPTS -Dlog4j.configuration=file:.\log4j.properties"
I don't know linux shell but I think the equivalent is this:
Set "OPTS=-Dlog4j.configuration=.\log4j.properties"
Then you can load the stored ...Options¿? like an argument:
Start Application.exe %OPTS%
".\" means the current directory of your script, ensure if "file:.\" means the same in linux OS.
I hope this is fairly simple but I'm struggling to get this to work.
I have a java package which I want to execute using a shell script command...
/jdk1.7.0/bin/java .path.to.classname.ClassToExecute >> /var/log/output.log
...so essentially...
./SCRIPT_NAME
...should run the above from the command line.
The problem is there is a classpath update needed every time first from the command line to enable the session to see a particular JAR...
export CLASSPATH=$CLASSPATH:/path/to/jar/file/lib/JAR_NAME.jar:.
If I don't put this line in first the shell script will not execute throwing errors of NoClassDefFoundError relating to the JAR I need to add manually.
Can anyone tell me where I need to edit this classpath update so that it's ALWAYS available to the script and also to the cron as ultimately I want to call it from the cron?
Thanks,
ForestSDMC
Your shell script should look like this.
#!/bin/bash
export CLASSPATH=$CLASSPATH:/path/to/jar/file/lib/JAR_NAME.jar:.
/jdk1.7.0/bin/java .path.to.classname.ClassToExecute >> /var/log/output.log
You also need to change the permissions of the script so that it is executable
chmod 700 SCRIPT_NAME
700 = owner can only execute the script
770 = owner and members of a group can run the script
777 = everyone who has access to the server can run the script.
Noticed that you want to run this from cron. You need to source your .profile either from the crontab entry or from within the script.
Just found the answer and works fine so hopefully others will find this useful...
You can dynamically generate the classpath variable within the shell script and then apply it as an attribute to the java command line execution. Like this...
THE_CLASSPATH=
for i in `ls /path/to/the/JARS/lib/*.jar`
do
THE_CLASSPATH=${THE_CLASSPATH}:${i}
done
/usr/bin/java -cp ".:${THE_CLASSPATH}" path.to.the.class.ClassName >> /var/log/logfile.log
I have a question regarding the creation of a utility that executes another command.
My script called notify will be placed in my /usr/local/bin directory and will do the following:
Execute the command that it was told to execute, then play a beep.
An example use case is the following:
> notify grep -r "hard_to_find_word" /some/huge/directory/
This is just an example, but could involve some other slower commands.
Essentially, notify will execute the grep, and then play a sound.
I know how to play a sound, but I do not know how to execute the provided command.
How do I execute the command that follows the call of notify?
Thank you for any input!
"$#" is all the arguments properly separated.
"$#"
I have a ruby script containing system command like http://gist.github.com/235833, while I ran this script from shell, it works correctly, but when I added it to my cron job list, it doesn't work any more, the cron job is like:
10/* * * * * cd /home/hekin; /usr/bin/ruby my_script.rb
any idea what's going wrong with what i've done? Thank you.
Thank you all for your answers.
It's my mistake.
Since I'm using ssh key forwarding on the local machine, while I executed the script from the shell, the ssh key forwarding related environment variables are all sitting there, but from cron job context, those environment variables are missing.
Try to separate the things that might go wrong. The ones I can think of are:
The cron syntax - is the time value given legal and fitting your shell?
Permissions - execute permissions and read permissions for the relevant directory and file
Quoting - what scope does cron cover? Does it run only the first command?
In order to dissect this, I suggest you first run a really simple cron job, like 'ls'. Next run a single-liner script. Next embed your commands in a shell-script file. Somewhere along these lines you should find the problem.
The problem is your environment. While testing in your shell its fully equipped and boosted by your shell environment. While running under cron its very, very stripped down.
Where is the destination "." for your script? I guess it will be "/" and may not "$HOME" thus your script won't be able to write at that location and fails. Try using an absolut path for the destination.