Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [shell-script]

Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

0
votes
1answer
16 views

Bash - Iterate through fmt -w and pass lines to a function

I have a multiline string and I want it first to be formatted to specific length per line before passing each line to a function for line processing. e.g. description="\ NOTE: This script ...
26
votes
1answer
2k views

What does ${!#} mean in Shell scripting? [duplicate]

Found this in an obfuscated malicious shell script, beginning with: ${!#}${*^} <<<... Could not find any reference to ${!#}, but when echo'd, it outputs -bash. Is this a secret referene to ...
1
vote
5answers
49 views

How to not display a column that has all NULL values in a file

I have a file that has let's say, 5 columns(obtained by redirecting the results of a Sybase select query). Each column is separated by a tab. I need to filter out the columns that have all NULLs. Any ...
0
votes
1answer
60 views

How to modify this `printf` code to accept input in first to last order, or flip output?

Code below can, for example ... [anony@mous-pc ~]$ (printf 'g?%s?m0\n' 008 006 004 002 ; printf 'wq\n') | ed -s file.txt ... take all of numbers within ... [anony@mous-pc ~]$ cat file.txt 005 003 ...
37
votes
6answers
121k views

How to pass each line of a text file as an argument to a command?

I'm looking to write a script that takes a .txt filename as an argument, reads the file line by line, and passes each line to a command. For example, it runs command --option "LINE 1", then command --...
1
vote
1answer
40 views

Command runs okay but not from bash script

Under ~/Pictures there are some sub-directories containing jpegs like ~/Pictures/Pics 1/img.jpg. From bash: ~/Pictures $ `file Pics\ 1/img.jpg` Output: Pics 1/img.jpg: JPEG image data, Exif ...
1
vote
1answer
1k views

Reload network interfaces without rebooting

I'm doing a BASH script for Arch Linux in a Raspberry Pi 2. The thing is that in some point I'd like to reload the network interfaces without reboot and have my new named network interfaces (en0 and ...
-1
votes
2answers
76 views

How to use SED or AWK instead of GREP as it is taking lot of time in shell script

I wrote the below code to extract the testcase name and the PASSED/FAILED status. The testcase log is like below: : In between there are so many lines. I just want to extract the testcase name ( say ...
2
votes
0answers
28 views

When coding for Unix/Linux is it convention to use a trailing slash on path names, or to omit it?

When programming for Unix/Linux, is it best practice to use a trailing slashbor to omit it? For example: Trailing slash baseDir="/path/to/dir/" #code# outPath=${baseDir}addition/to/path/ No ...
0
votes
1answer
41 views

Run bash script upon change

I am running a FreeBPX on centos server and I would like to monitor phone extensions when they go offline. I have a script that is doing the job and I am running it on cron job every 30 minutes but I ...
0
votes
1answer
20 views

How to start my application after starting of “daemon” process in single script

I have a script, that starts my server. I want to start openvpn client before it. Here my current working solution: #!/bin/sh openvpn --client --config $OVPN_CONFIG & sleep 10 npm start I ...
82
votes
11answers
227k views

How to compare two dates in a shell?

How can two dates be compared in a shell? Here is an example of how I would like to use this, though it does not work as-is: todate=2013-07-18 cond=2013-07-15 if [ $todate -ge $cond ]; then ...
1
vote
0answers
31 views

Round Robin (RR) scheduling in Bash Unix Shellscript

I want to simulate CPU scheduling algorithms using Unix Shellscript but the loop in round-robin doesn't end when the shell script is executed. I can't figure out on how to fix the code. Here's the ...
0
votes
0answers
10 views

Adjusting the table and Gantt Chart for CPU scheduling

Is there a way to adjust the contents of the table and Gantt Chart for CPU scheduling? The code is mostly translated from C. Code for the table: printf "Program Name\t Arrival Time\t Burst Time\t ...
0
votes
2answers
195 views

Open and tile windows with shell script

I cannot find this answer anywhere. No idea where to start. How do I open let's say nemo. I know I can set the window size using -geometry. But how do I tile it on a specific monitor/quadrant? I'm ...
1
vote
2answers
30 views

Bash command to rename files and convert datestamp from 'dd[st/nd/rd/th] mmm yyyy' to 'yyyymmdd'?

Is there a simple bash command that will match the date string in a filename like this... File Name 20th May 2019 descr.txt (File Name and descr are strings of variable length) ...and convert it to a ...
0
votes
1answer
50 views

Why is my bash shell script changing spaces to linefeeds?

I started out writing a simple bash shell script to find duplicate files within a given directory using SHA1 to detect matches. Everything worked until I encountered file names with spaces. The ...
0
votes
1answer
42 views

Writing continuously to named pipe

I have a problem that I can't seem to solve involving two named pipes. Basically, I have two processes that I don't have control over. They are communicating via named pipes (mknod pipe p). Process ...
0
votes
0answers
29 views

Continuously detect a change of chksum of files under folder with inotify-tools [duplicate]

I just installed inotify-tools. I would like to continuously detect change of chksum of files under folder /path Once a change was detect ( under /path ) then it will print echo “chksum of files ...
-1
votes
1answer
27 views

Shell script for telnet for multiple servers from text file

I am using below code for to telnet the multiple servers. file=ip.txt while read line do ip=$( echo "$line" |cut -d ' ' -f 1 ) port=$( echo "$line" |cut -d ' ' -f 2 ) if telnet $ip $port </...
-1
votes
0answers
26 views

how to know if files chksum was change under folder

under /home/app/Jars we have files ( many jar files ) we want to restart the /home/app/kasandra.sh restart once chaksum of files under /home/app/Jars was change how we can do it? example how to ...
0
votes
0answers
20 views

Running .bsh error (ZereneStacker)

I am trying to run the program ZereneStacker on Linux (I am using a Chromebook Samsung 3). I downloaded the program's .zip from here and extracted it. According to that download page, the .zip file ...
0
votes
1answer
80 views

Parsing bash output

#!/bin/bash start(){ printf 'Real IP: %s\n' "$(curl -s ifconfig.co)" set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn shift $(( RANDOM % $# )) screen -S vpn -dm openvpn "$1" # connect ...
0
votes
2answers
37 views

bash + regular expression + capture java version [on hold]

how to capture the jdk1.8.0_112 under /usr/jdk64 /usr/jdk64/jdk1.8.0_112/ while jdk1.8.0_112 is example and could be any other version as jdk1.7.0_112 jdk3.8.2_112 jdk1.8.0_117 jdk1.2.0_112 jdk2....
0
votes
0answers
16 views

Linux command to decompress the files in directories and add them back to one archive

Is there a way to decompress gz files in the directory, sub-directory and then add them back to a new gz archive with the same directory and sub-directory structures. There are more than 8k files and ...
20
votes
6answers
24k views

Are there any well known and well used shell scripting IDEs for Un*x?

Are there any IDEs targeted at shell scripting, specifically bash and zsh scripts? This means having syntax-highlighting for shell scripts and more importantly debugging environments with features ...
1
vote
1answer
29 views

Is there a way to create a symlink to a non-existent target?

Is there a way to create a symlink whose target does not exist using shell scripts? From reading man 1 ln, I do not see an option to do so; and even -f checks if the target exists. Is there a way to ...
0
votes
1answer
20 views

Output reads “ 13test.sh: line 5: [: missing `]' ” but adding brackets then directs the error to a nested if statement

The goal is to take line of usernames and then run the w command on it if it matches the who search or say that the person is not online otherwise. read -p "Enter User ID's: " str for i in [ $str ]; ...
0
votes
2answers
20 views

SED or AWK to remove everything before the first dash and after the last

I have a private key file with some extra nonsense in there, and want just the text of the key. so: nonsense -----Begin Key----- keep this1 keep this2 keep this3 -----End Key----- nonsense should ...
0
votes
0answers
7 views

Security Firewall Software [on hold]

Linux comes with open source netfilter/iptables based firewall tool to protect your sever and desktop from the crackers and hackers. UNIX operating systems comes with its own firewall ploduct (for ...
0
votes
2answers
47 views

Persist SSH Command

First off, I know about tmux and screen. My conundrum: I started a shell script over SSH expecting it would take a short amount of time, so I left my computer on overnight. I can't terminate and ...
-5
votes
1answer
47 views

Get specific string from specific point of line [on hold]

From the below line I need specific fields only in following format: 031100000080,Z45G0001,09:43:08.5234999,09:43:09.7925597,0:1:269,737683 Input line: 17/05/2019 09:43:09.792559|TraceDetail |...
1
vote
2answers
28 views

How to Preserve last most directory structure when copying files using find

Using "parents" command works but it copies complete directory structure, whereas I need to preseve only the last most directory find /tmp/data/ -type f -name "*.txt" -exec cp --parents {} /u01/ABC/ \...
16
votes
4answers
15k views

Bash: interactive remote prompt

I have a script which connects to a remote server and check if some package is installed: ssh root@server 'bash -s' < myscript.sh myscript.sh: OUT=`rpm -qa | grep ntpdate` if [ "$OUT" != "" ] ; ...
-1
votes
0answers
12 views

grep specific string from each line after every specific string format [duplicate]

From the below line I need specific fields only in following format and the format can be change in other lines so it shouldn't be constant like get string from bracket or from index. 031100000080,...
3
votes
2answers
71 views

How to include custom command options in a bash script with $1 and $2?

I have a script myscript.sh #!/bin/sh echo $1 $2 which is used something like ... ./myscript.sh foo bar which gives me an output of ... foo bar but how can i make this script include custom ...
0
votes
1answer
42 views

find the depth of nested parenthesis each line in a text file?

and print the number of dots (or any random characters) representing the depth at the beginning of each line the shell script should have 3 parameters. The first is character c, the second is the ...
0
votes
4answers
42 views

Read the data page wise and store in seperate files

I have a huge text file where data in seperated pagewise.for example The Text is in below format i want to read lines page wise and store in seperate files Page 1 line 1 line 2 line 3 line 4 ...
1
vote
1answer
42 views

Bash script to connect to *.ovpn randomly

I'm trying to edit the following bash script to connect to vpn randomly from the list of .ovpn files inside the directory. I've downloaded the following ovpn files from nordvpn List of NordVPN OVPN ...
4
votes
3answers
1k views

Unable to assign output of nested commands to variable in bash

I was trying to assign below command(which choose the random line from file) to a variable, but not working. givinv@87-109:~$ head -$((${RANDOM} % `wc -l < file` + 1)) file | tail -1 cower givinv@...
1
vote
3answers
917 views

ffmpeg command fails silently inside script but works when run directely

Have a script that generates a rtmp stream that runs inside a screen using ffmpeg but this fails for some reason? If it run it directly in the command line it works so I tried to run it by opening > ...
0
votes
1answer
40 views

Get all characters between two double quotes [on hold]

I need to implement the shell script which should return all type of characters between first and last occurrence of double quotes in a variable. Eg: String="The \"hz:"jnz::\\\gb""+₹+_)*s\"hdhz\"...
2
votes
1answer
28 views

How to make a system suspend and resume on schedule?

I have a Linux server that's only needed at workdays in work hours. There's no point having it powered on all the time. How can I make a Linux system suspend and resume on set times and days without ...
1
vote
1answer
2k views

run pm2 from remote shell script

I am trying to write a script which ssh into a bunch of my servers and runs some commands to start my app. One of the commands (pm2) always says pm2: command not found. This is how I'm attempting this:...
0
votes
4answers
327 views

remove string ends with certain extension in a file

Need to remove .sql entry in file I have file which contains strings ends with both .class and .sql and I need to remove only string which ends with .sql in the file file.txt actual.class actual1....
2
votes
4answers
190 views

Duplicate a file multiple times, write to duplicated files, sort the files, count position of specific lines after sorting

Before I go to more in details, I want to point out that I already asked a certain part of this question -> You can find it here. I received some nice answers, but I need to do more so I'll repeat my ...
0
votes
1answer
42 views

Building a for loop around exsisting loop, to replace user input

I basicly have this script: #!/bin/bash #Asks For filname and Word echo 'Which word are you looking for?' read word echo 'What's the name of the file?' read fileName #Searches word and parses the ...
0
votes
1answer
14 views

Remote screen session

This is running me crazy: I want to use 4 screen windows (within the same session) in a remote server (GCloud) to process 4 subjects in a parallel way. Long story short: I first create a detached ...
5
votes
1answer
1k views

Listing files from nested zip files without extracting

I have a set of nested zip files and I need to list the file names without extracting the archives. For example: Zip1.zip text1 text2 Zip2.zip Sample1 Sample2 with some shell scripting should ...
1
vote
1answer
360 views

touchpad not working after hibernate

I'm using an up to date Arch/Antergos Linux. My touchpad stops working after resuming from hibernate. I seem to be affected by this bug and I need to type sudo rmmod i2c_hid; modprobe i2c_hid after ...