Questions tagged [scripting]

A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

Filter by
Sorted by
Tagged with
0
votes
2answers
41 views

Re-order the fields of each record in a file based on the order given as input to the script

I have a file, having multiple records, each with a number of fields. File content is like below. # cat inputfile name: AAA age: 38 city: C1 state: S1 age: 29 city: C2 name: BBBbbbB state: S2 ...
0
votes
1answer
17 views

WSL distro disappeared after running history | script

I have a Windows Subsystem Linux installation (the distro is Ubuntu). I use it to build a Rails project and deploy branches to the server. Things worked OK for the last year. Today I accidentally run ...
-4
votes
1answer
62 views

How to generate the following numbers

I need to generate a sequence like this one: 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14 What's going to be the code like?
0
votes
1answer
97 views

Create bash script for ping

Good evening I would need a script in bash that follows this command: ping -c 4 -i "IP" for 3 times. Each ping must be performed at a distance of 10 minutes and only when it fails all 3 times, it send ...
-3
votes
0answers
59 views

Validating all IP address using shell script by doing nslookup

Am doing the nslookup of DNS using script nslookup.sh which resolves only 1 IP at a time. If that scripts resolves any one IP out of 4 IPs it return true else it return fail when ip not resolved. I ...
44
votes
7answers
32k views

Autohotkey Equivalent?

Is there an equivalent product/method for AutoHotkey. For those that don't know, its a product that allows you to program your mouse movements and keyboard. This allows me to "macro" certain functions ...
0
votes
0answers
22 views

How to Switch user and run a command as that user?

I wanted to set up a script that switches users and runs that command as that other user. so example sudo su myFavoriteUser && /run/command/as/myFavoriteUser Any help would be appreciated. ...
0
votes
0answers
27 views

How to write a script that sends kill signals if a process can't finish in s time? [duplicate]

I can't find any solutions for this problem anywhere. How to write a script that waits a process to finish, but if that process can't finish within s seconds, the script will send a signal TERM to ...
1
vote
5answers
54 views

How to restructure a date variable in bash

I have a bash script that takes user-inputed dates in this format: dd.mm.yyyy and saves it as a variable $date Now I need to modify this variable to be in this format: yyyymmdd for further use. So ...
1
vote
2answers
45 views

ed(1) script with multiple search/replace

Working on a question for codegolf.se, trying to do a simple text replacement. Given a file coin.txt containing 1 word, either heads or tails I have an ed script flip.ed as follows: s/heads/1/n\ s/...
-1
votes
0answers
51 views

How to use files that I dont know the name of yet as input for a script

I have a bunch of files in a set of folders, all this folders start with the name Case and then the name of the case for example: casePI648864_R1.fastq.gz. Inside every folder then like for every ...
7
votes
2answers
713 views

Safest way to store environment variable value in a file

I am using bash and most interested in an answer for bash, but you can answer about how to do it in other shells if you want. I have an environment variable, KEY, and I want to store the value of ...
0
votes
0answers
17 views

Change specific settings with gsettings/dconf key. (archlinux, linux-lts-4.19)

I am trying to change the "custom-command" value for the Tilix terminal emulator in dconf from python3 $HOME/Scripts/memux/main.py to python3 $HOME/.pps/pecan.py, but I can't figure out the format for ...
1
vote
0answers
16 views

How to increase the duration of the transition effect between multiple video cuts in this ffmpeg `-filter_complex` command

As instructed in Gyan's solution to this question, ffmpeg can be used to interleave two audio/video inputs with a lapse dissolve transition. For example, this command will divide each input into cut ...
0
votes
1answer
25 views

How to write a csvcut script to cut column by header with multiple files?

Since csvcut (from csvkit) does not take more than a single file at a time, I need to write a script to process multiple files using it. The first parameter should be the delimiter, the second ...
0
votes
1answer
878 views

Terminate established tcp connection using iptables

I have an open socket connection, and I want to close it immediately if packet passing through contains certain string. I have tried the following using iptables: sudo iptables -A INPUT -p tcp --...
0
votes
0answers
67 views

how to grouping timestamp and value with awk

i have some complicated log and need grouping by minutes and value. below some sample log : 2019-08-09T19:01:53:594+07:00 - info: {"tag":"request /browse","tagName":{"status":"05","message":"...
1
vote
3answers
64 views

Bash: Running sed operation with file input

I am trying to use sed in a bash script with a file as input. When I run the same command in command line, it works. But when I use the file as an input to a script with the sed command, I get sed: ...
8
votes
4answers
20k views

How to check if the current time is between 23:00 and 06:30

I am having trouble grasping how to properly check from a bash script if the current time is between 23:00 and 06:30. I am trying to run an infinite loop to check the time now, and to do something if ...
1
vote
1answer
872 views

How to put the percentage of use of each core from cpu

I use the Zabbix Server to monitor my environment. The metrics used by Zabbix to view the CPU are too confusing, so I would like to simplify. Is there a way to get the percentage of use of each core ...
-1
votes
1answer
26 views

I'm working with VS Code editor. Is there a way to force the -x switch in there somewhere for ShellCheck?

In terminal if I run: shellcheck -x my_script I get no error, but if I run it without -x: shellcheck my_script I get this notification: . ./functions/my_function ^-- SC1091: Not following: ... ...
1
vote
1answer
930 views

rc.local can't find my script

I am trying to get my script to run on startup. I am using Ubuntu Server 16.04. Here are the exact contents of /etc/r.local. #!/bin/sh -e # # rc.local # # This script is executed at the end of each ...
0
votes
1answer
35 views

sed: -e expression #1, char 1: unknown command: `''

I have already read a similar question, but there is no solution to my problem. I want to delete some line in some file I use sed in the script this is the code. line="this" del='echo "'/"$line"/d'"'...
37
votes
9answers
53k views

Is there a unix command that gives the minimum/maximum of two numbers?

I was looking for a command to limit numbers read in from stdin. I wrote a little script for that purpose (critique is welcome), but I was wondering if there was not a standard command for this, ...
-1
votes
0answers
27 views

I am new to running more complex commands on the command line and need help figuring out what is going wrong here [migrated]

I want to run a one-liner to enable me to get the hash of a string and eventually compare it to a hash I can just copy at the end of the command later. I'm confident I can figure out how to do the ...
1
vote
2answers
45 views

How to add a newline to a “no-text returned” from ssh command

Within a Qt5 application I have a bash script which runs to check version numbers from certain files on other remote machines (that I ssh into). I have over 100 machines that I can run this script on....
2
votes
3answers
68 views

How to grep data of a new line when capturing a keyword?

I have a file which contains below sample line having a common keyword P00001121 in each line. [H00,P00001121] CHANNEL__OPEN:TCP_ADDRESS='10.32.130.202' TCP_PORT='80'" [H00,P00001121] COMMS_QUEUING:...
6
votes
3answers
100 views

Replace MAC address with UUID

I am looking for a way to mask the client MAC address every time it appears in a logfile before using the logfile to present data to a customer (GDPR rules). I can identify the MAC string using regex,...
17
votes
4answers
3k views

Using Python in a Bash Script

If I try to start python in a bash script, the script will stop running and no commands will execute after "Python" is called. In this simple example, "TESTPRINT" will not be printed. It seems like ...
-2
votes
0answers
25 views

Replace text between non-matching sgml tags [closed]

I want to replace everything in a file, what is between <!-- Marker -->……</dl> and put it in another file. That is, everything between the non-matching sgml tags (Where the …… is). How ...
0
votes
1answer
48 views

Linux Bash Script Parsing Unknown output with Known Delimeter

I'm writing a recon shell script and I would like to parse the output of odat sidguesser so i can save only the found SID's into a file or variable. For example. I have the string; [+] SIDs found on ...
1
vote
2answers
621 views

How to remove arbitrary subtitles formats from mkv with a shell loop

I made this script to remove ALL subs from all mkv files in a given path. It works ok. But now I want to only remove PGS subtitles and keep all SRT files, no matter the language. for file in "$@"*...
5
votes
2answers
2k views

How to get drive SERIAL number from mountpoint?

If lsblk -o NAME,SERIAL,MOUNTPOINT includes the following in its output sdb X55MM4827123 └─sdb1 └─luks-4d0dc651-9aa6-452d-9442-7b33d95f8427 /...
0
votes
2answers
1k views

Command puts in expect doesn't show the message in the order it should

I have a some scripts to automate a process and I want the message about which step I am in it shows in the command window. A piece of code I have is: puts "** Creation of $VMNAME on $HOST begins... ...
1
vote
2answers
29 views

Rsync how to exclude all arch without amd64

Have make little script on Linux that's intended to rsync, excluding all arch without amd64, but it is downloading all arch's. What is wrong with the script? #!/bin/sh # This is a sample mirroring ...
0
votes
2answers
43 views

Check mandatory argument of parameters

I have script with several parameters that have required argument: while [ "$1" != "" ]; do case $1 in -f | --first ) shift first=$1 ...
1
vote
0answers
22 views

Need a script or commands to distribute files into folders [duplicate]

I have in one folder a lot of files. each file has diferent sizes. I have 3 folders and I need to fill them with files up to 15gb total on each folder. is it possible to automatate the process?
1
vote
1answer
36 views

Fedora terminal script to create a directory and copy a file to directory

I need help to write a script to create a directory, so far I have mkdir ./directory. This would create a folder called Directory, but I need to make it ask if the user wants to copy a file called ...
44
votes
15answers
180k views

Automatically run commands over SSH on many servers

There is a list of IP addresses in a .txt file, ex.: 1.1.1.1 2.2.2.2 3.3.3.3 Behind every IP address there is a server, and on every server there is an sshd running on port 22. Not every server is ...
1
vote
2answers
8k views

lftp sftp file to specific directory

I need to copy a file over SFTP to a specific directory. I use LFTP because this connection requires an IP6 mDNS name. lftp sftp://admin:password123@serial.local -e "put file.txt; bye" This works, ...
2
votes
1answer
712 views

Ideas for parsing netstat results for active connections

I have several remote devices that create reverse ssh connections back to my server, so that I ssh to them and manage them remotely. They connect back to me via a custom port. When I do a netstat -...
1
vote
1answer
1k views

Bash, find and delete old files

Write script to backup files and delete old backups: #!/bin/sh BACKUPDIR=/var/backups/files ROTATE=1 mkdir -p $BACKUPDIR CURRENT="$BACKUPDIR/`date +%Y-%m-%d`-files.tar.gz" cd /var/ && tar ...
0
votes
0answers
33 views

Why is my bash variable not working properly? [duplicate]

I have a csv file that I use as a lookup for my script. It contains system names, their IP, and a port number: $ cat ips.csv sys1,2.2.2.2,4444 sys2,2.2.2.3,4445 In my script, I take the system name ...
2
votes
1answer
34 views

curl in non-interactive mode

I am trying to automate stuff which includes installing rust through curl https://sh.rustup.rs -sSf | sh . This is interactive and queries for user-input to choose from i.e. "1" "2" or "3". I am ...
-1
votes
1answer
43 views

year should be 4 digits only , only then script should paas

I mean $yy should be 2019, 2020, 2021, etc. $yy should fail if it is 20199 201987 It should be 4 digits only. How to check this condition.. yy =$1 if [ $yy > 4 ] ----- something like this then ...
3
votes
2answers
134 views

Passing lines from the text file of a list of files to or as arguments [duplicate]

I have a file which has two file names per row, like this: file1.fastq.gz file2.fastq.gz ... file9fastq.ga file10fastq.gz How can I pass the two names as arguments for a script?
0
votes
1answer
19 views

i3lock called by the i3-nagbar starts in the background

I am trying to set up a lock script with the i3⁻nagbar command. The current code i have: i3-nagbar -b "lock" "i3lock" -b "shutdown" "shutdown -h 0" And while the shutdown button works, the lock ...
3
votes
2answers
45 views

Remove duplicate values that aren't on identical lines

So I have a set of text that contains both the file names and an associated number. Currently it looks like this: RR0.out -1752.142111 RR1.out -1752.141887 RR2.out -1752.142111 RR3.out -...
4
votes
1answer
881 views

GRUB 2 scripting: convert device name in GRUB notation into a Linux device name

I'm trying to use partition labels (or UUIDs, that does not matter) to select root partition without use of an initrd/initramfs. With initramfs, this is fairly easy: root=LABEL=... or root=/dev/disk/...
1
vote
1answer
36 views

Kill bash script if Terminal is closed

Problem is that i have a bash script that requires user to login and perform operations. Everything is logged in a log file. Now issue is if user exits the terminal, the scripts keeps running and ...