All Questions
Tagged with command-line script
242
questions
1
vote
1
answer
542
views
Writing a batch script to copy files based on date
I have a folder on a local PC that updates files through Dropbox. I have created a batch script that runs through a scheduler each day.
So far it checks to see if a folder is empty (C:\TheGlenFTP\...
1
vote
0
answers
348
views
Creating a script for Windows 11 to gzip some files using 7-zip then move and replace them in another folder
I have the following directory structure:
Parent Folder: Project
Children of Project: data, rawData
Inside of rawData I have: index.html, settings.html, user.html, script.js, style.css and other files....
3
votes
2
answers
455
views
SSH remote command with nohup not working as expected
I wanted to run a long running command in a remote server, even after the connection terminates. So I thought of using ssh host "nohup cmd &". But for some reason, neither cmd is going ...
3
votes
2
answers
3k
views
Extract text between two strings from a file and save the output
How to extract the text between two strings from a file and save the output to another file, and invoke it in batch, at command line?
To be more specific, let us say that the input file is SomeFile....
1
vote
1
answer
173
views
What is the equivalent of Linux's && for windows
What is the equivalent of Linux's && for windows
For example
cd\
cd rcA
powershell "ls | where {$_.Length -lt 100gb} | Remove-Item -Force -Recurse"
What to add to make the script ...
0
votes
1
answer
191
views
Linux RHEL 7 - Shell Script - Can execute command separately but cannot execute inside a script
I have a simple script use to install a package under cust privilege like this (command changed for security)
installScript.sh
#!/bin/bash
patch -i <package-name> << EOF
n
EOF
the purpose ...
-1
votes
2
answers
2k
views
copy files from server share to C:\Temp and then run the batch file that is copied locally
I need a login script to copy the contents of a directory from a file share to the local computer, and then run a bat file that gets copied locally as part of that process.
if not exist "C:\Temp\&...
-1
votes
2
answers
543
views
Windows Command Line Scripting - Prompt for value
I have a windows script that simply moves and renames files from one directory in to a series of subdirectories. I would like to have the script prompt the user for the date of the files. Currently I ...
1
vote
0
answers
188
views
How to save each page of a PDF file into separate files, and name them from text file of file names
I have a large PDF file, as well as a text file of file names. I'd like to use the command line to make/save one new PDF file for each page in file.pdf and name them with the file names in names.txt. ...
1
vote
2
answers
364
views
WMIC ProcessID does not get parsed within the same command instance
I've got a batch script that I'd like to capture its Process ID but the PID is not being parsed from within the same command instance.
For example, running the batch script with the following code ...
1
vote
2
answers
520
views
Duplicate Results from Batch File
I created a batch file that gives me the ability to input a computer name and it will tell me who is logged into the device as well as the serial number of that device. I pull these two specific bits ...
0
votes
1
answer
714
views
How to delete a line based on a regex string in Powershell?
I want to validate if the line above a certain line is there, then ok. if else, then delete that line and remove the empty space ? Can this be done in powershell? please help
If before all lines ...
1
vote
2
answers
6k
views
How do you run PowerShell scripts from the command line, instead of opening Notepad?
After adjusting the PATHEXT and PATH environment variables, PowerShell scripts can accessed from the Command Prompt. The issue comes, however, is that when attempting to execute a script (ie, CMD> ...
0
votes
1
answer
227
views
Bash script vs command line
I have started working on bash scripts.
I have just observed a difference between executing a command line and executing the same commands but inside a script. In particular the command line is:
for a ...
0
votes
1
answer
124
views
Windows CMD Scripting: Why SET don't work inside parentheses?
Actually I want to redirect output to file like
@echo off
(
set res=fail
echo %res%
) > out.log
And redirection itself works fine... But why %res% is empty inside the parentheses?
@echo off
...
1
vote
3
answers
87
views
Run two executables after one another from different locations in batch file, with spaces in a filename and pass commands to the other
@echo off
cd "C:\Program Files (x86)\World of Warcraft\"
start "World of Warcraft Launcher" "World of Warcraft Launcher.exe"
cd "C:\Program Files\obs-studio\bin\...
0
votes
2
answers
746
views
How to programmatically disable OSX from charging?
How can we programatically disable OSX from charging when connected to power source?
And how can we programatically check the current battery percentage?
In order to extend battery life I'd like to ...
2
votes
4
answers
2k
views
Run bash scripts without typing the file extension the right way
I'm on Windows 10 and decided to transition from cmd to Git Bash. Say I have a script foo.sh, I'd like to be able to run it with the command foo and not foo.sh. I found this answer, which works in ...
0
votes
0
answers
869
views
ffmpeg command into batch command
I was trying to get an command I use and have to apply to batch list of files instead of doing it for each file.
Command I use for ffmpeg (has to keep -i and -c) - ffmpeg -i in.ts -c copy out.mp4
How ...
0
votes
1
answer
654
views
I need to restart my PC if theres no network connection after about 1 minute
I manage a number of Microsoft teams rooms. They do a nightly reboot and sometimes they come up without network. The environment they are in is very locked down so no ICPM traffic is allowed. What Im ...
2
votes
1
answer
2k
views
How do i return true/false on get-content command for each username inside C:/Users?
We want to eliminate the existence of a bad config file we've identified (and also have the manual fix for) from within every users appdata folder. The config file only exists here and there and not ...
0
votes
0
answers
1k
views
Run powershell script from anywhere in the PC
Powershell script, on my Desktop screen, that executes commands on files in a certain folder. When I run the script on the desktop, it works, but when I move the script to another location, it doesn't ...
2
votes
1
answer
186
views
Script to iterate on all utf8-based files and rename them based on content found [closed]
You may skip the following which is a preface that provides some context to what I am trying to do:
I have a lot of files which are data points of a Nasa satellite (MERRA-2) of different cities. When ...
0
votes
3
answers
116
views
Using --my_argument `cat some_file` as argument to some command
I'm running a command with options/parameters based on files.
So I cat the files inside the command.
However, when there's nothing in the file, this is problematic.
mkbootimg --kernel "$...
0
votes
1
answer
3k
views
rename all files within a directory and its subdirectories with batch script
I would like to rename the name and the extension of all files which are located in the a certain directories and its subdirectories to a random combination of 25 alphamuneric signs (letters and ...
1
vote
1
answer
145
views
How to define and use global, filenames in a bash script
EDIT: Changed the requirement for dynamically-calculated variable names as I don't strictly need this for my use case, and a solution was provided that works for me.
This is probably impossible to do, ...
0
votes
1
answer
313
views
How can i undo this command
i recently found a post on a website and it said follow the solution and it will repair you cast in windows, but nothing happened after i did that, now i have question is it kind of hacking? How can i ...
2
votes
2
answers
1k
views
Can I run python scripts as regular commands in Windows 10?
I have some utilities scripts written in Python. Is it possible to configure Windows 10 so that I could run those scripts as regular commands? For example I have an utility script that iterates over ...
0
votes
1
answer
1k
views
How to create an outbound rule for a program via the command line?
I have several programs that I'd like to block from accessing the Internet. A manual (i.e. point-and-click) solution is described here.
Is there a way to do it via the command line on Windows 10?
...
0
votes
0
answers
73
views
How can I obtain the names of the Windows lockscreen "Spotlight" locations?
I already have a little batch file that I run every so often when I see a photo I like on the Windows lockscreen, but it would be nice to be able to remember where it was taken (you know how in the ...
1
vote
1
answer
2k
views
How to make apache service run continuously from script file from docker?
I am trying to run apache2 service from .sh script from dockerfile. The 'sh' script contains 3 executable commands which is presented as below:
#!/bin/bash
export DISPLAY=:0.0
echo "pvw ...
0
votes
1
answer
29
views
CLI script works. Alias script broke. Corrective action is?
This CLI (Command Line Interface) script works.
This script is 688 characters with spaces.
This script shows: directories, files, totals in
current directory and
recursive directories (down the file/...
0
votes
1
answer
1k
views
PowerShell - Close running script with another script
I have 3 PS Scripts, STOP.ps1, FORM.ps1 and ENABLE.ps1.
ENABLE.ps1 will create a task in task scheduler that opens the FORM.ps1 script every hour.
Once the FORM gets opened, there is a button to close ...
0
votes
0
answers
194
views
script that will monitor changes in at least 2 files/directories and execute a third script only when both are modified
I have two sensors that each create an entry in a text file when triggered. Now I need something to monitor these two files (i can also put them in 2 directories each if that helps in any way) and ...
0
votes
1
answer
222
views
Run .cmd file every x minutes when app is being used?
I'm trying to find a way to incrementally back-up a folder every 15 minutes, but only if VS Code has been used/in focus since the last time it was backed up.
Does anyone have an idea for how I could ...
0
votes
0
answers
26
views
How to create file with current date into folder with Windows cmd? [duplicate]
I am quite new to scripts so I am mostly googling things, but I was unable to find exactly what I am looking for.
I need script that will write output to file with current date as name. But this file ...
0
votes
0
answers
1k
views
How can I get the current monitor on which a window is present. I'd like to get the name/ id of the output the window is present on
While I was making a script on Linux which manages multiple monitors and windows present on it, I want to have some command 'x' that can output the current screen the window is on so I can put it ...
1
vote
1
answer
107
views
Access positional parameters out of order in a for loop
I have a script which makes use of multiple (i.e. positional) arguments from the command line, and within it a for loop that iterates through these arguments:
for i in "$@"; do
...
done
...
1
vote
0
answers
602
views
Can't run VBS files in Command prompt
In a beginner coding course that wants us to use command prompt to execute various types of files we created in notepad. I have run JavaScript and Python files, but whenever I try to run a VBS file I ...
1
vote
2
answers
3k
views
Tar extract a stream of tar files
I've got a binary (lets call it displayFiles) which will get several tar files at once and print the tars to stdout. I then pipe the stdout to tar.
This works fine when the binary only downloads a ...
1
vote
2
answers
2k
views
Inside cmd batch script recursive for loop, get matched files path relative to script file
I am trying to achieve this by substracting %~dp0 from %%~dpa, where %%a is the for loop variable. If anyone is aware of a better way to do this, please advise.
My code is as follows:
@echo off
...
1
vote
1
answer
563
views
Windows Admin Center (WAC) + Powershell
so I'm using a PowerShell script which runs .exe installation,
both the script and the .exe file located in the same network folder,
when I run the script directly from the pc it runs well,
but when I'...
0
votes
1
answer
2k
views
Intune Win32 app batch script installation can't run as user
TL:DR When trying to install and run a .bat script file via intune Win32 app the install behavior is stuck on SYSTEM and greyed out, but the batch script requires to be run as current logged in user.
...
1
vote
0
answers
948
views
How to place continuous numbering on PDF?
I want to place continuous numbering on a pdf document 1.5cm from the page edge. The numbering should run from the top to bottom of every page. This is similar to line numbering, however the ...
6
votes
1
answer
767
views
On Windows, how to make a .bat or .ps1 file automatically elevate itself when running?
I have pinned admin cmd and admin pwsh to taskbar, I know how to run .bat files as Administrator, just right-click->"Run as administrator", for .ps1 files, I have modified openwith of ....
2
votes
0
answers
1k
views
Extract all rar files in a folder and subfolders using 7zip [closed]
I have the following folder structure in Windows:
D:\TV Shows
|
\----Show
| |
| \----S01
| | |
| | \----E01
| | | |
| | | \----E01.rar (contains E01.mkv)
| | ...
0
votes
1
answer
380
views
how to give a variable value is empty in bash scripting
I'm trying to export 2 dashbords into two different files, Here in the loop 1st dashboard id is reading and value is storing {ES_HOST1}, then the {ES_HOST1} coming into empty, then in the loop 2nd ...
0
votes
0
answers
388
views
How can I update the date of a renamed folder in batch?
The problem is when I start the script it will copy the folder and rename it and add the current date and time to the name. But while the script is running and changes in the folder were made it would ...
1
vote
2
answers
259
views
Batch File That Keeps Other Batch Files Running
I run 3 .bat files on my computer at all times 24/7 for a business that I have. Every now and then they will close because of my internet drops due to the area I live in and they need internet to run.
...
1
vote
1
answer
1k
views
Windows rename multiple files from multiple folders having pattern
I have a folder in which there are multiple sub-folders(only one level) which has multiple files.
Names have some dynamic prefix that I want to remove based on pattern in it.
1. ...