Cygwin bash script-Windows 2003-Scheduled tasks not working problem

Posted on 2007-07-27
Medium Priority
Last Modified: 2013-12-16
I have a windows 2003 server with cygwin installed.

I have written a bash script in cygwin that will let me tar a directory and ssh the tar dynamically over to another server (backupserver = remote linux server):

YDATE=$(date -d "1 day ago" +%d)
MONTH=$(date -d "1 day ago" +%m)
YEAR=$(date -d "1 day ago" +%Y)

tar cfz - /cygdrive/c/backupdir|ssh backupuser@backupserver "cat > /backups/backup."$YEAR"."$MONTH"."$YDATE".tar.gz"

This script runs fine under the non-admin user i have setup, backupuser, on the windows 2003 server, when doubleclicking  the script c:\backup_process.bat, contents below:

c:\cygwin\bin\bash --login -c "bash /cygdrive/c/Documents\ and\ Settings/backupuser/backup.sh"

My situation now is that I want to automate this backup procedure. My first thought is to avoid installing the cron service from cygwin, and instead use the scheduled task function of windows 2003.

If I create a scheduled task under Administrator on windows 2003 set to run c:\backup_process.bat then the process works perfectly. the scheduled task runs at the right time, a dos prompt pops up and starts the tar/ssh process. However, I dont want to run this as Administrator.

Problem #1: logging on as backupuser and attempting to create a scheduled task, being non-admin, does not have access to "at" or scheduled tasks

Problem #2: if I create a scheduled task under Administrator on the windows 2003 server and set it to run as backupuser, then the task _shows_ as "running" in Scheduled Tasks, but no dos prompt pops up and the files are not backed up to backupserver.
The Scheduled Task log shows:

      Started 27/07/2007 12:09:00
"backup.job" (backup_process.bat) 27/07/2007 12:11:21 ** WARNING **
      The task was terminated. This action was initiated either by an administrator or by the Task Scheduler service (because, for example, the computer is now non idle).

The user backupuser on windows 2003 is part of the "logon as batch job" group in secpol.msc.. I can only conclude it's something to do with cygwin.

any ideas please anyone?


Question by:daryn
  • 2
  • 2
LVL 27

Expert Comment

ID: 19589516
> The user backupuser on windows 2003 is part of the "logon as batch job" group in secpol.msc.. I can only conclude it's something to do with cygwin.

Can you give access to backupuser to run scheduled tasks and then just try to schedule task from this user?

Author Comment

ID: 19590949
have tried to figure out how to give the non-admin user "backupuser" access to run scheduled tasks but on the whole damn worldwide web there appears to be nothing that clearly says "here is how to do it" that i've found, apart of course, from making it part of the admin group..

tell me how and will do pls? :)

Author Comment

ID: 19592769
sorted it out..although the user backupuser could run the job manually (ie it had the ssh keys in cygwin setup), the administrator user could not access the backupuser's ssh keys when the scheduled task ran as backupuser.

did some shenanigans and ran cygwin under administrator as backupuser and created ssh keys, then ported them over to the linux server, works now.
LVL 27

Expert Comment

ID: 19597315
That's OK that everything works now.

You may reclaim your points, just you ask in community support to close and refund points for this question and mark it as self answered.

Accepted Solution

Computer101 earned 0 total points
ID: 20246397
PAQed with points refunded (500)

EE Admin

Featured Post

SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
This installment of Make It Better gives Media Temple customers the latest news, plugins, and tutorials to make their Grid shared hosting experience that much smoother.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question