How to run ansible playbook and see if a task running a script is waiting at a prompt? - ansible

When I run a script in ansible, if it pauses to prompt for something, I am not seeing that prompt (e.g., tar -xvf sometarball.tar). It prompts to say it is there already and asks to overwrite it with y/n. Yes, I have ways to deal with that, but I was curious if there was a way I could have seen when I run the playbook that it was sitting at a prompt waiting for something? Using -v[vvv] does not seem to help. I found it by going on the vm and running the script manually.

Related

How to send input to a console/CLI program running on remote host using bash?

I have a script that I normally launch using the following syntax:
ssh -Yq user#host "xterm -e '. /home/user/bin/prog1 $arg1;prog2'"
(note: I've removed some of the complexities of the command, so please excuse if there are any syntax errors in the ssh command; it should not be relevant to the question)
This launches an xterm window that runs prog1, and after completion runs prog2. prog2 is a console-style program that performs some setup, then several seconds later waits for user input.
Is there a way via bash script (preferably without downloading external packages) that I can send data to prog2 that's running on $host?
I've looked into << and expect, but it's way over my head. My intuition is that there's probably a straightforward way of doing this, but I can't figure out what terms to search for. I also understand that I can remotely send keystrokes to a host using xdotools or something similar, but I'm hesitant to request a new package installation unless I know that's the only reasonable solution.
Thanks!

Continue script after reboot with crontab in a terminal [duplicate]

This question already has answers here:
How to have a Shell script continue after reboot?
(3 answers)
Closed 3 years ago.
I have a bash script to install some stuff in linux. The install script needs to be run as root. The installation process reboots twice and continues after each reboot.
I managed to manipulate the crontab to add/remove jobs to get that working. However, I would like the user to be informed if the install script has finished or not, so he/she can wait until the last reboot has finished.
The only solution I could think of was to run the crontab job in an open terminal, so the user can see the installation is still in progress.
Question 1: Is this a good solution? Any alternative?
Question 2: If the solution is good, how can I make sure a terminal is opened and the crontab job is run in that terminal?
Cron jobs are executed without any attached terminal. You'll have to create one in your cron script, and redirect all output from your script's commands to it. Maybe the simplest option is to redirect your script's output to a logfile, and open a terminal which just does tail -f <logfile>. You can then kill the terminal when your script is complete. If you're using xterm (as an example), you can do xterm -e "tail -f logfile.txt".

Psexec failing when running multiple commands in sequel

Using windows task scheduler i am running multiple commands, I'll call them task1.bat, task2.bat, and task3.bat . Each one of these scrips runs a different Psexec command (psexec version 2.11).
When running task1.bat, task2.bat, and task3.bat indivdually, these scripts run successfully; however when run in succession, task1.bat will run successfully, then task2.bat and task3.bat will usually fail with the error "Couldnt access servername. Access is denied. The syntax of the command is incorrect".
It seems like an error with Psexec, since when run individually the commands works fine. Is there a way to force Psexec to exit/end before moving onto the next script (besides just putting in a timeout)? It seems like psexec is hung which is causing the next to fail.
The .bat script will run sequentially if you create and run the batch file:
CALL task1.bat
CALL task2.bat
CALL task3.bat

running shell script with windows task scheduler

I currenty have a simple shell script that I created for a linux machine to be run using cron, but now I want to be able to run the file using windows task scheduler. I have tried to get it to work using cron for cygwin, but even after running cron-config successfully and ensuring that the shell script can be executed successfully, for some reason the cron task simply wasn't executing. So I decided to give in and use the windows task scheduler. In order to do this, I looked at the following posts about the issue:
Cgywin .sh file run as Windows Task Scheduler
http://www.davidjnice.com/cygwin_scheduled_tasks.html
in my case, the entry in the "actions" tab of the new task looks like this:
program/script: c:\cygwin64\bin\bash.exe
arguments: -l -c "/cygdrive/c/users/paul/bitcoinbot/download_all_data.sh >> cygdrive/c/users/paul/bitcoinbot/logfile.log 2>&1"
start in: c:\cygwin64\bin
Notice that I redirected the output of the shell script to a log file, so that I should be able to see there whether the program run. Other than that, I simply edited the "trigger" tab to run the task daily, and set the time to a couple of minutes in the fture to see whether it ran successfully.
Alas, when I look at the detailed event history for the task, nothing changes when the trigger time passes. And when I manually "run" the task, the event history seems to add a few different events, but the task is completed within seconds, whereas this task should take over an hour (and it does when the shell script is executed directly from the terminal). And when I look for the log file that should have been created, there is nothing.
Does anyone have any idea what might be the issue here? How can I get my task to run properly at the trigger time, and how can I make sure it does so?
Best,
Paul
EDIT:
here are the pictures showing event history, as per Ken White's request.
Please ignore the fact that it says there are 24 events. These are from multiple separate runs of the task. The events shown here are a complete list of the events triggered by a single run.
EDIT 2:
Regarding my attempts to get cron to work, I have run into the following problem when I try to start the cron service using cygrunsrv. First of all, I tried to start cron by typing
cygrunsrv -I cron -p /usr/sbin/cron.exe -a -D
Now when I type
$cygrunsrv -Q cron
Service: cron
Current State: stopped
Command: /usr/bin/cron.exe
Now, I tried to start the cron service by typing
cygrunsrv -S cron
Cygrunsrv: Error starting a service: QueryServiceStatus: Win32 error 1062:
The service has not been started.
Does anyone hae any idea what this error means? I tried googling it, but couldn't find any answers.

Running remotely Linux script from Windows and get execution result code

I have the current scenario to deal with:
I have to schedule the backup of my company's Linux-based server (under Suse Linux) with ARCServe R15 (installed on Windows 2003R2SP2).
I know I have the ability in my backup software (ARCServe) to add pre/post execution scripts to my backup-jobs.
If failure of the script, ARCServe would be specified NOT to run the backup-job, and if success, specified to be run. I have no problem with this.
The problem is, I want to make a windows script (to be launched by ARCServe) for executing a Linux script on the cluster:
- If this Linux-script fails, I want my windows-script to fail, so my backup job in ARCServe wouldn't run
- If the Linux-script success, I want my windows-script to end normally with error code 0, so my ARCServe job would run normally.
I've tried creating this batch file (let's call it HPC.bat):
echo ON
start /wait "C:\Program Files\PUTTY\plink.exe" -v -l root -i "C:\IST\admin\scripts\HPC\pri.ppk" [cluster_name] /appli/admin/backup_admin
exit %errorlevel%
If I manually launch this .bat by double-clicking on it, or launching it in a command prompt under Windows, it executes normally and then ends.
If I make it being launched by ARCServe, the script seems never to end.
My job stays in "waiting" status, it seems the execution code of the linux script isn't returned to my batch file, and this one doesn't close.
In my mind, what's happening is plink just opens the connection to the Linux, send the sript execution signal, and then close the connection, so the execution code can't be returned to the batch. Am I right ?
Is what I want to do possible or am I trying something impossible to do ?
So, do I have to proceed differently ?
Do I have to use PUTTY or CygWin instead of plink ?
Please, it's giving me headaches ...
If you install Cygwin, you could do it exactly like you can do it on Linux to Linux, i.e. remotely run a command with ssh someuser#remoteserver.com somecommand
This command will return with the same return code on the calling client, as the command exited with on the remote end. If you use SSH shared keys for authentication instead of passwords, it can also be scripted without user interaction.

Resources