Installed Cygwin, wrote my script, tested successfully. However when I go to run it as a Windows scheduled task it fails. Further digging is showing that not all programs are available when running the script in this manner. For example Launching Mintty and typing in ls
will list the contents of my directory.
Running bash.exe from the Windows CLI will put me in a Bash prompt, but ls
is not a recognized command.
I have tried the standard
c:\cygwin\bin\bash.exe -l -c "/home/user/logoff.sh"
as well as the
c:\cygwin\bin\mintty.exe /bin/bash -l -c "/home/user/logoff.sh"
I added an echo command that outputs to a text file, and that works so I know the script is getting called. The issue appears to either be with the various programs not being available, or it doesn't like the piping I am doing.
This is the script I am trying to run.
for user in user1 user2 user3 ;
do
id=$(query user $user 2>> /dev/null | awk '{ print $3 }' | sed -e '/ID/ d')
if [[ "$id" =~ ^[1-9][0-9]?$ ]]; then
logoff $id
echo "$user was logged off" >> logg_off.log
fi
done
Any ideas?
Here is some more information:
- I fat fingered the file name in the scheduled task, which is why it failed to run.
- Still not sure why the script would fail to finish. I removed all but one user from the list and everything works as expected. Will have to wait until this evening to test whether or not I can log off the other users in one pass.
/usr/bin/awk
and so on