Link to home
Start Free TrialLog in
Avatar of tdemeyer
tdemeyerFlag for Belgium

asked on

Starting scheduled job from command-line ?

One of our servers has several jobs scheduled to run every x minutes, using a special user account.

Problem we face is that once in a while we need to start those jobs ahead of their planned time.

What happens now is somebody opens "Scheduled tasks", selects the task, right clicks, and select the "run"-option.

Can we do the same using the command line?
Avatar of JammyPak
JammyPak
Flag of Canada image

'at' can schedule jobs from the command line, but you'd have to schedule it for 1 minute in the future or something.

Can't you just type in the command line that the task uses and hit enter?
Avatar of tdemeyer

ASKER

Final goal is to put everything in a batch job, making it easier for the (novice) user to start thos sheduled jobs.

Problem with just entering from the command line is the fact that those scheduled jobs are not running in the logged-on user's context. "runas" cannot be used, as we don't want to give away that account's password ...
Well, AT is the command-line version of the scheduler, so you could use AT to schedule the jobs for any point in time that you want. It doesn't run in the logged-on users' context, so the user won't need to know any passwords.

You could put all the tasks into a batch file and use AT to schedule that batch file. It would be really cool if you could grab the current time, and substitue current time + 5 mins (or whatever) into the AT command line....hmmm...
Ok,
But how can you enter the account's password (in non- human-readable format)?

You don't enter passwords for the 'at' command...here's a page with the syntax:
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/winxppro/proddocs/at.asp

Hmmm...it says you need to be a local admin to run 'at' - so this may not be ideal for you. I think the commands run in the context that the 'Task Scheduler' service is running in (probably 'Local System Account'). No one needs to be logged in at the time the scheduled jobs run...
That's right, we use AT quite often on our machines...

Problem is, when you create a scheduled job using the GUI, you must supply the user/password the job has to run in/under, but that's not possible with AT.
schTasks is another utility, but there again: password has to be provided in clear text...
Well,

solution was quite simple at the end:

schTask.exe can start a job, simply by entering the job's name  (as found in sheduled tasks) in the parameter list.



schtasks : one of the parameters enables you to start a named job, configured via sheduled tasks.

You simply use the name of the job in the parameter, and it fires up. No need to supplu usernames/passwords, as they are encoded in the task's jobfile.
ASKER CERTIFIED SOLUTION
Avatar of GhostMod
GhostMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial