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

Posted on 2007-07-27
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/"

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
    LVL 27

    Expert Comment

    > 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

    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

    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

    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.
    LVL 1

    Accepted Solution

    PAQed with points refunded (500)

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
    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.:

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now