Questions tagged [shell-script]

A shell script is a script written for the shell, or command line interpreter, of an operating system.

Filter by
Sorted by
Tagged with
2 votes
1 answer
37 views

PowerShell : Watch a folder and when file created, send it by mail

I would like to create a script watching a specific folder in my computer, and if a new file is created, send this file by email. What I found : $action = { $WatchFolder = "C:\Users\..." $To ...
  • 41
1 vote
1 answer
25 views

Execute EOF command remotely in one line

I am facing a problem. If I execute this command, it works normally, but I need to execute it using SSH connection. Is there a way to do it in just one line of command? Thank you for your attention. ...
0 votes
0 answers
18 views

multi-part Shell command running out of order

I'm running a shell command and when I was testing the 3 pieces needed to parenthesis, and maybe that's the issue, but it's sometimes running the pieces out of order, which makes a difference when I ...
  • 190
2 votes
3 answers
68 views

Delete all folders except if they have a specific file type in Linux

I looking for a command or bash script to delete all folders except if they have a specific file type (*.pdf) in the first level subfolder. folder01 a.txt y.txt folder02 b.pdf z.txt folder03 ...
  • 123
0 votes
1 answer
12 views

How do I create a script to run 2 commands in 2 different windows?

I have an app that uses Flask on the backend and React on the frontend. All my app files are under C:/Users/moonman239/Documents/App My Flask app is in one directory, and my React app is in another ...
0 votes
0 answers
29 views

shell script getopts options validations

I'm trying to check if all the validations are true and work but my logic I think is not correct and I'm new to coding. So I initialized p=0 and un=0, when user passes both option it should give error....
0 votes
0 answers
21 views

Bash: simplify variable replacement/upper-casing?

Is there any way to cleanly simplify this into a single line? # e.g. ARG='--some-arg' ARG=${ARG/--/} # some-arg ARG=${ARG//-/_} # some_arg ARG=${ARG^^} # SOME_ARG I'm hoping for a syntax ...
  • 1,476
1 vote
0 answers
32 views

Does tput automatically check color abilities when loading color codes?

When using tput setaf and tput sgr0, does it automatically output nothing if the session isn't tty-like or no color support is detected? So am I fine doing this? declare -r styleRed=$(tput setaf 1) ...
  • 11
0 votes
1 answer
23 views

expect spawn command: Escaping newline (\n) in string

I am trying to use expect to interact with the MATLAB console. Currently I have: #!/usr/bin/expect -f spawn {*}/usr/bin/run.sh matlab -r "fprintf(1, \"The identifier was:%s\\\\n\", \&...
0 votes
0 answers
21 views

Source alias from script

I'm having difficult in passing alias in shell script. Basically I want to execute script once alias is executed. As per my understanding, alias will create sub shell and I cannot run rest of script #!...
0 votes
1 answer
37 views

put list of IP addresses into config file as text

I have config file for fail2ban where I try to put multiple IP addresses automaticly with script. But I am probably doing some mistake as the script is spamming ignoreip = ip in a loop till the fille ...
  • 113
0 votes
1 answer
44 views

How to retain last file of every day and delete remaining for the dates in linux

Case: I have a folder in Linux where the files huge files will be created/generated every day. Now I would like to retain the last file and delete the remaining files every day Example ...
1 vote
1 answer
40 views

expect -timeout vs. "set timeout" in expect: Different behavior

I was testing a expect script and found two different behaviors when using set timeout vs. expect -timeout. Here is a simple example response.sh: #!/usr/bin/bash sleep 2 echo hello test1.sh: #!/usr/...
0 votes
0 answers
15 views

What's the best way automate sorting files into folders based on a dictionary correspondence between the file name and folder?

I periodically receive a folder full of jumbled files that looks something like this: [Alice A] Messages 2020-01-03.zip [Bob B] Messages 2020-01-05.zip [Carl C] Messages 2020-01-08.zip [Alice A] ...
0 votes
0 answers
82 views

Check Windows Defender Date Last Updated and update signatures if 90 days out of date in PowerShell and Bash

I need to Check Windows Defender Date Last Updated and update signatures if 90 days out of date in PowerShell What is the proper way to do this check in both PowerShell and Bash? Here is what I have ...
1 vote
0 answers
14 views

Execute a command after matching a specific rule of iptables

Is it possible or is there any way from which a bash script can be executed using iptables? Like I wanted to execute a bash script if incoming traffic on a udp port crosses 1000pps I tried searching ...
  • 27
0 votes
1 answer
36 views

cron.d script launching then dying

Many stack posts seem to suggest something like: * * * * * root /usr/bin/pgrep -f 'socat -T10 TCP4-LISTEN:22222,fork UDP4:localhost:22223' || (/usr/bin/socat -T10 TCP4-LISTEN:22222,fork UDP4:localhost:...
4 votes
1 answer
612 views

How to always execute a command when a shell script function finishes?

I need to write a zsh function with multiple exit points and execute the same clean-up command at every one of them: function foo { if ... ; then ... run_cleanup return ...
  • 2,829
0 votes
2 answers
31 views

if-then statement in bash to toggle screen resolution

How do I phrase a script that checks screen resolution with xrandr and changes resolution depending on what it is currently? Which is to say, toggles the resolution. Sample output of xrandr -q ...
0 votes
2 answers
57 views

Issue with running a shell script without using 'sh' on macOS Monterey

I'm new to shell scripting and generally the usage of Terminal. I recently made a script.sh that I want to use by just typing its name without the full path. So, I wrote the path of the directory into ...
  • 3
0 votes
0 answers
82 views

How to log Linux commands ran from a script?

I am able to log commands executed on bash shell using export PROMPT_COMMAND='history -a > ..... , but this wont log commands executed from within a shell script. Is there any way to log command ...
2 votes
1 answer
3k views

Run powershell script, as administrator, via batch file with parameter passing

When I run the script, without an administrator, via batch file it passes the parameter, but when I run the script, as an administrator, it does not pass the parameter. I tried the command from the ...
  • 539
0 votes
1 answer
64 views

Change names within a text file

I have mixed music projects, where the software generates a txt file list of the songs in each project. The problem is that the list is generated with only the first 36 characters of the name of each ...
  • 539
0 votes
0 answers
21 views

How can I generate background keystroke in a shell script?

I'm intending to run a background shell script for keeping some security related application alive which seems detect key/mouse input for a specific duration. I prepared a script. #!/bin/sh while true ...
  • 326
1 vote
0 answers
175 views

FFMPEG - merge (NOT concatenate) multiple sets of 2 videos in for loop

I have a folder A with mp4 audio. Folder B has mp4 video. The filenames match, expect that they are in different folders. These are movie files that when they were downloaded came in two separate ...
0 votes
0 answers
227 views

How to create a Scheduled Task that runs a Power Shell script once on next reboot then never runs again?

On Windows 10, is there a way I can create a scheduled task that kicks off on the next system reboot or user login but then never runs ever again? Currently I can create a scheduled task that runs on ...
1 vote
1 answer
199 views

How to not expect return code from nohup command from remote

env : centos7, lang : bash enter image description here If I call wasctl from a remote server, ssh remote1 "./wasctl start" it hangs forever after running everyjob successfully. It turns out ...
  • 139
0 votes
0 answers
31 views

How do I list OID Names along with their associated OnNotificationAction Triggers with PRTGAPI using Powershell?

So I'm trying to pull a list of Group Names with their corresponding notification triggers using PRTGAPI, Get-Sensor | Get-Trigger gives me ObjectId & OnNotificationAction but I am struggling to ...
2 votes
1 answer
61 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
1 answer
105 views

Backup with all metadata preserved but converting file content into zeros (or empty sparse file)

I want to make backups of a directory, everything the same as original files, only except for file content converting to all zeros (sparse files), and also keep the same file size. So for example, I ...
0 votes
1 answer
458 views

Excluding a specific folder's content from deletion

So I have a one-liner for deleting content from multiple folders, but there is 1 folder whos contents I do not want to delete. So if I had folders A, B, C, D, and E, I want to delete all files from ...
  • 61
1 vote
1 answer
631 views

in batch For loop , echo %%i:~0,5% doesn't work

Why doesn't this command work? How can I correct it? for /F %%i in ('dir c:\logs /A:-D/B') do @echo %%i:~0,5%
  • 11
0 votes
1 answer
39 views

Refining a simple delete-item one-liner

so I was wanting to upgrade my delete-item one-liner. I want to breakup the main filepath(\HQDEVAPP004\C$\LoneStar\ProcessorHandlers\Test) into 2 variables that are defined at the top of the script. ...
  • 61
1 vote
1 answer
80 views

How can I get my Lubuntu system to "beep" via bash script?

Running Lubuntu 20.04LTS, and trying to get a nice beep when a bash script finishes. Before anyone votes this down, I have tried: beep and sudo modprobe snd-pcsp and say and echo -en "\007&...
  • 161
0 votes
2 answers
1k views

How can I have a terminal window persist beyond the script it was opened for? (NOT just "keep the window open" or start a new shell)

I am not especially tied to using a shell script for this purpose, but my requirements are as follows: I can double-click an icon on my desktop. (This is intended to select an optional, alternate way ...
2 votes
2 answers
4k views

mv: target 'XXX' is not a directory

I am trying to write a bash script that will go through a directory and rename the files (the file name is really crazy and is not recognizable to any human as what they are) to "Chapter1.mp3&...
0 votes
0 answers
30 views

Cronjob not working properly when run as scheduled

This file is placed in /etc/cron.weekly/ : #!/bin/sh # For syncing some files with OneDrive # Assumes that the sync target is set up as OneDrive:Syncs in rclone if [ $(id -u) -eq 0 ]; then exec ...
1 vote
0 answers
454 views

Start-Process elevated powershell & send a variable to be used when running elevated script

When this scirpt is executed(non-elevated) this script asks password and maps onedrive and then it automatically launch powershell(elevated) and asks again password for bitlocker. If single password ...
  • 397
-1 votes
1 answer
420 views

Is there a way to see what command are run on your computer?

I was wondering how I could see the actions that are done on my computer but on my cmd prompt. For example: Imagine I click on the shortcut Google Chrome on my desktop, then this will appear on my cmd ...
  • 1
0 votes
1 answer
26 views

Sending FreeBSD script output by email loses format (left aligned and right aligned in one line)

every day I am running a script on my router to check the traffic usage of a specific server. The script is working fine and with this output part of the script, I get following result: #Give output ...
0 votes
1 answer
159 views

[SHELL SCRIPTING SMALL PROJECT]

I am currently trying to complete this shell script for a small project I have for my class. I'm lost as to how to go about this problem. Here is the prompt and what I have so far... What I have so ...
2 votes
0 answers
17 views

Unable to launch UI of java application which is executed by scheduler executed by system user [duplicate]

I have a python script which runs via windows task scheduler, I have to launch a javaFx application jar from this python script, when I execute the python script from cmd it launches the jar, also it ...
0 votes
0 answers
54 views

`run-one-constantly` not working as expected

I am running a script that monitors a directory for incoming file which must be processed as fast as possible. To avoid downtime if the script crashes, I used a cronjob calling run-one <script> ...
  • 151
0 votes
0 answers
31 views

Shell script to replace config file if server fails to go online after config change

So, my situation is as follows; Due to CoViD restrictions I can't physically access a remote (debian 11) production server, but I'm forced to add/activate two physical network ports (NICs) on that ...
  • 101
0 votes
0 answers
417 views

Sending a post request via curl for a variable with double quotes

I am trying to send POST request via curl command which has a variable and the variable is having an escape character like this curl -r POST 'https://<url>/admin/v1/Apps/.search' --header '...
  • 11
0 votes
0 answers
152 views

DockerSwarm High Availability with keepalived

I'm trying to use keepalived with Dockerswarm so that in case a manager node goes down, a worker node takes it place, and so the virtual IP bounces from the old manager node to the new manager node. I ...
  • 1
-1 votes
2 answers
59 views

Comparing date inside if command in SHELL

I was trying to run the following shell script in linux, but for some reason, it is not running properly, I am getting the output of no even when the date matches. Can anyone suggest what is wrong ...
-2 votes
1 answer
261 views

List/Print oldest and newest file in each directory

Could use a bit of help guys. I need to produce a report for the oldest and newest files that are residing in each unix directory The structure is simple Main folder with multiple subfolders that ...
1 vote
1 answer
651 views

Understanding how pgrep determines process IDs

I'm currently refactoring a script that works well if executed in terminal directly but exits early due to a process check if executed from crontab. This early termination is caused by code using a ps ...
  • 13
0 votes
1 answer
634 views

How to download the latest release from github and extract the zip in a folder using bash

I want to write a bash script to download the latest release from a github repo and extract the downloaded zip into a particular directory. From this gist I am able to download the zip file. The shell ...
  • 3

1
2 3 4 5
28