PostgreSQL uninstall on Windows - windows

In the process of upgrading from PostgreSQL 11 to 12 on Windows, I uninstall PG-11 using the uninstall.exe, wait for like 15 seconds (to make sure that the uninstall.exe is complete), delete the bindir (if exists) and then install the Postgres-12.exe. This all is done in a batch file and the code looks something like:
uninstall-postgresql.exe --mode unattended
PING 1.1.1.1 -n 15 >NUL
if exist C:\PostgreSQL\bindir RD /Q /S C:\PostgreSQL\bindir
postgresql-12.1.exe --servicename Postgres --prefix C:\PostgreSQL\bindir --datadir C:\PostgreSQL\datadir
On some systems, the uninstall-postgresql.exe completes in less than 15 seconds and the upgrade works.. however on some slow systems, it takes more than 15 seconds due to which the Postgres-12 installations will fail for some or the other reasons.
I want to remove the 15 seconds delay and make sure that the control is given back to the next command in the batch file only when the uninstall-postgresql.exe is 100% complete. Right now, when I run the batch file, it calls the uninstall-postgresql.exe --mode unattended but the control comes back to the batch file and the next command (in the batch file) is executed while the uninstall-postgresql.exe is running in the background. Is there a way to make sure that uninstall-postgresql.exe completes and only then the next command in the batch file is executed?
Please recommend if there is any way to do so.
Thanks in advance.

Related

Restart .bat file every 12 hours

i have a batch file on my server desktop called start.exe. I'd like to kill start.exe every 12 hours, than wait 2 seconds, and than restart start.exe. This should of course also work when no user is logged in on the server. So the workflow should be like:
Starting Windows Server
Starting start.exe
Restart every 12 hours
How can i achive this? With a script? With a task?
Run shutdown.exe in a scheduled task set to run every 12 hours. At a command prompt, type shutdown /? to see the options.

Run a batch file 5 minutes after startup in Windows Xp

I want to execute a .bat file 5 minutes after windows starts up. Unfortunately, windows task scheduler doesn't offer anything of the sort, only execute something right on start up. However, I need something to be 5 minutes after startup.
.bat file doesn't do much, just calls one separate .cmd file and passes a parameter. I've tried:
timeout /t 300 /nobreak
"C:\Documents and Settings\Administrator\Desktop\sikuli\runIDE.cmd" -r "C:\Documents and Settings\Administrator\Desktop\sikuli\SikuliXmlTestRunner.sikuli"
However, the runIDE.cmd gets called right away, regardless of the timeout.
You can give wait(300) command at the beginning in your sikuli script to achieve this.
XP doesn't have timeout command, use ping -n 300 localhost>nul or ping -n 1 -w 300000 localhost>nul.

I would like to create a batch script to run an already made bat script, delay for a few seconds and then type some commands

Need some help with this one (I'm new to batch scripting). So here's the problem:
I have a batch file called connection.bat:
- it connects to a network WiiU console, but it takes a few seconds to load the environment
- after it loads, it looks something like this:
#userid:
- that's when you can type some specific console commands (install and run mostly)
I want to make a batch file that does the following:
1. runs connection.bat
2. waits for it to finish loading the environment
3. and then type the install command
I tried doing it this way:
cd C:\test\connection.bat install -1 10.xx.xx.xx testupload.pkg
but it doesn't work, because it needs to connect first to the console
Is there a way to do this?
I always use ping to add a delay in batch files:
ping 0.0.0.0 > nul
adds a 3 second delay

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.

User session timeout force logoff

I have been doing a little research on how to make a script using vbs or batch to set a session time limit for users logging onto a specific set of computers linked through Group Policy.
I am not familiar with log off or timed scripts, I can make the simplest batch script to log the current user off a machine. The problem I get to is not being able to set a timed session, or running the log-off script due to the time limit.
I researched setting it through group policy, then came up with the idea of linking a script to a group policy in the start up for users on the certain set of computers.
I found a vbs by googling key phrases but I am not sure exactly how to implement it with the log off script or how to make it begin its count down
echo.
echo Waiting For thirty minutes...
TIMEOUT /T 1800 /NOBREAKS
echo.
echo (logoff)
echo.
pause >nul
The log off script that I was planning on using goes along the lines of:
shutdown -l -f -t 30 -c "Your 30 minute session is over."
But I cant get the comment to display and the 30 second time doesn’t take affect.
Any help would be greatly appreciated. Thank you for reading.
How about somthing like this?
Set oSystems = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
For Each oSystem in oSystems
oSystem.Win32ShutdownTracker 3600,"Logging off...",0,4
Next
I know this question is old but here you go anyway:
have a .vbs file called invis.vbs and place it in the Startup directory of the user you want to be limited.
It should contain the following (replace #username# with the Username):
wscript.exe “C:\Users\#username#\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Start-up\invis.vbs” “C:\SessionLimit.bat”
Now save the below as a batch file called SessionLimit.bat in the C:\ Directory.
It should contain the following:
#echo off
timeout 1800 /nobreak
shutdown /l ;;Replace this comment with /f if you want the log off to be forced without the Do you want to save your work interruption window.

Resources