Need to schedule Cygwin Expect Script with Windows Task Scheduler - cron

I am currently in the process of implementing a backup scheme to run a Cygwin Expect Script. What I would like to do is have task scheduler open Cygwin and run an expect script called Backups.
The issue that I run into is what I believe to be either variable or path based. I have the correct user from Active directory (we'll call it AD/svc_backup) set, and I am currently trying to just see if I can get the task scheduler to open Cygwin.
So far it will only open the program if I have the run only when user is logged on radio button pressed. This will open cygwin, but not let me run any further commands and gives me an error.
For example ls gives me "bash: ls: command not found" When it asks what program I want to start, I simply point it to the shortcut on my desktop and it then fills in the path C:\cygwin\bin\mintty.exe . Task scheduler does not seem like the most intuitive tool IMO but if I can get it to work I will use it. I also know that cygwin can use cron as well. Would cron be a better option?

I figured it out. So what the system means by the button "run only when user is logged on" radio button pressed" means is I want the script to run and I want to see it run with the local usr account. (interactive with the user)
The "run whether the user is logged in or not" button turns whatever script or program you run into a background service that has no user interactivity( you cant see it). By using the full path under the actions tab in cygwin I was able to tell it which script to run. Script path and options are like so:
C:\cygwin\bin\bash.exe -l -c C:/cygwin/home/svc_p_cisco_bkp/
I have been researching the -l and -c arguments and from what I can gather the -l means list the output and the -c means run these commands. This was not listed anywhere but from what I read it is as educated of an answer as I can give. Also I tested and the script will not run correctly without these variables.
I don't see the script start when I check the "run whether the user is logged in or not" button, but I can see the backups going to my destination folder. I do see it when "run only when user is logged on" however. What I did was get the script running the way I wanted while I could see it and then choose the "run whether the user is logged in or not" radio button when I know it was working correctly.
All is up and running and after exhausting reading of pages and pages about Windows task scheduler, and I am fully automated.

Related

Silence login info when not using a display manager

I want to silence the login info provided in tty after the boot-log/boot-screen and drop me directly to shell. What I get after the boot-screen is complete.
Run 'nixos-help' for the NixOS manual.
CosPi login: creator54 (automatic login)
after this I get a shell prompt.
I know I could just add a clear on topmost of my shell config, but it takes some time to reach the shell after the boot-log/boot-screen is complete and the OS gets stuck in this info for few(~15) seconds. So adding clear does't do much here as i'll still see the info.
If you can control what files the home of the user you are logging in contains, you can disable the messages by adding the file .hushlogin to the home directory. It does not have to contain anything, just do
touch .hushlogin
(I have not used this on NixOS, but this .hushlogin is a very old feature that works on other Linux distributions, and also on Solaris, FreeBSD etc).

How do I grant a cron job webcam access in Mac OSX Mojave?

In OSX Mojave, access to the camera is controlled by pop-up dialogs and the new System Preferences>>Security & Privacy>>Privacy>>camera panel, where apps can be granted (or denied) access to the camera.
I can grant "iterm2" access to the camera, which lets me run imagesnap from the commandline.
I use a cron job to capture a photograph of the cat bed every 60 seconds. This now fails, since upgrade to Mojave, because it does not have permission to access the camera. Is there any way I can give my cron job access? I don't get a pop-up dialog for a cron job.
Using an Automator application wrapper also works. Create the wrapper (run shell script), run in manually and grant it permission. Then the cron job can call the Automator app.
I hacked around this by using a wrapper script that indirects through Applescript to use iTerm, which does have permission, and have cron launch the wrapper.
#!/bin/bash
osascript << EOF 2>&1 | grep -v "window id"
tell application "iTerm"
create window with default profile command "/path/to/capturescript"
end tell
EOF
FWIW - Mojave broke this further, and the Automator app broke.
I lost a lot of time fiddling with it, and then gave up. It seems the security of camera devices changed again. My time is expensive and raspberry pis are cheap; I connected the camera to a pi and now access it from cron with "ssh pi fswebcam - > output.jpg" which works flawlessly.
Open Automator on Mac.
Click New Document.
Choose Application.
In search bar search for Run Shell Script and add to application with click.
Add code for running your desired script (like you would run the script from shell).
On top right click Run.
Allow access to camera.
With installed cronjob you should be fine.

Will zip -r command on remote server be cancelled if I exit terminal?

I have done a lot of Googling, and cannot find an answer.
I have made a "zip -r home" request on my server via my terminal.
The home directory is over 30GB. I need to leave the office at some point with my laptop.
I was assuming it should not matter, as the request was made on the Linux OS on the server, and my PC being online or offline should not matter at all. However, the terminal is showing me up to date status of the zipping process, which made me think twice before exiting.
Would the zip process be cancelled if I exit the terminal?
If not, how can I see the status again, once relogged.
Excuse me if this is a very basic question, I am a newbie and could not find a solution searching on Google.
Thank you so much
Yes, it will stop because your session no longer exists.
You can use screen utility.
you just run your command with:
screen zip -r ...
While its executing you press Ctrl+A followed by D (this is called detach)
In that moment you can disconnect from your session. It will continue zipping your folders. If it finishes before you come back the process will close as normal and your zip file will be complete.
you can check if there is something "screened" with screen -list and you can attach yourself back again with screen -r <id>.

How to automatically start and advance a few steps in an application in background in linux?

I'm using Genymotion to run WhatsApp on Ubuntu 13.04 as I don't own an Android.
To get to Whatsapp everytime I login, I have to
1) open terminal and run ~genymotion/genymotion
2) click a button on the GUI which opens up another new window (play button).
3) wait for about 30s for the device to get ready.
How can I make the computer do these first two steps automatically for me at start up?
Even better if it possible to do them in background, i.e., I shouldn't see the GUI opening. It should perform the steps and be "minimized".
I was thinking if there was a way to record what my click does and then put it in a script.
Something like a strace command.
I hope my question is clear enough. I'm relatively new to Linux.
For now Genymotion allows you to start a VM from the command line, by calling the "player" binary, and passing the VM name as a parameter.
You could write a shell script that:
run: <GENYMOTION PATH>/player --vm-name <VM NAME>,
wait some seconds for the VM to boot: sleep 10,
then use adb to start your Application: adb shell am start -n com.whatsapp/com.whatsapp.Main
Luckily, no need to simulate clicks for this.

How do I logout from a computer using shell?

How can I log out of my computer using shell such the log-in window appears again?
I need this functionality in one my Linux script.
Update:
I want to replicate the code working behind the Logout button of my Ubuntu.
Desktop Enviroment being used: GNOME
I think this does the job:
gnome-session-save --logout
Also, take a look at the --help output, maybe you want to use the --force-logout option.
Usage:
gnome-session-save [OPTION...]
Help Options:
-h, --help Show help options
--help-all Show all help options
--help-gtk Show GTK+ Options
Application Options:
--logout Log out
--force-logout Log out, ignoring any existing inhibitors
--logout-dialog Show logout dialog
--shutdown-dialog Show shutdown dialog
--gui Use dialog boxes for errors
--display=DISPLAY X display to use
Your question is a bit vague. Are you trying to log out of a graphical session of a desktop environment (such as KDE/Gnome), as if the user clicked on "log off"?
Then you need to find out if/how the desktop environment supports scripting to log out. On KDE for example you can use kquitapp.
Try restarting the display manager using one of the following, depending one which one you're using. You'll obviously have to have the proper permissions.
/etc/init.d/xdm restart
/etc/init.d/kdm restart
/etc/init.d/gdm restart
It's a bit of a hack, but the way that screen's power detach does this is to determine its parent pid and send it a SIGHUP. (Clarification: This closes only the shell, so only works if you're running from a console - not a graphical login - so may not be what you're looking for.)
Type in terminal
gnome-session-quit
or
pkill -kill -u {Username}

Resources