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
6 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
11 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
0answers
14 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
0answers
11 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
0answers
23 views

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

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
24 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
20 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
2answers
45 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 ...
1
vote
1answer
25 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 ...
0
votes
0answers
14 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 ...
0
votes
2answers
33 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....
1
vote
1answer
28 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
0answers
12 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
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
18 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
1answer
70 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
46 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 ...
-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,...
-5
votes
1answer
45 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 |...
0
votes
1answer
40 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 ...
3
votes
2answers
66 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 ...
1
vote
2answers
27 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/ \...
2
votes
1answer
27 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 ...
0
votes
1answer
36 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\"...
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 ...
1
vote
1answer
40 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 ...
-2
votes
1answer
22 views

Find package (OS distribution) manager for automation [on hold]

I want to automate some installation process. For that, I need to know whether it is a DEB or RPM distribution, Im able to find some scripts for find the OS distribution. I need to write a script to ...
2
votes
5answers
120 views

Filter a file list against an integer array?

I have a folder with lots of images named "clip01234-randomlongstring.png", where 01234 is a random five digit number. I also have an array "clipnumbers" with a list of integers. Now I want to ...
0
votes
0answers
26 views

How to end pipe from consumer side and put producer in background

Say I have a server writing stdout to a consumer my server | upon 'some pattern' --exit=0 so basically when the consumer reads stdout, and sees a certain pattern it will exit. my question is - when ...
0
votes
0answers
25 views

Use read -e path in variable [duplicate]

I'm trying to get a path from user input and use it as a variable in a command: read -e -p "Path to backup: " path mongodump --host localhost --port 27017 --db my-db --out $path When I put there ~/...
0
votes
2answers
33 views

How to run next bash line even when set -e is switched [duplicate]

Say I have something like this: set -e; echo 'doing some stuff' false; status=$? post_hook send-message-elsewhere-with-status $status One way to do what I want is: set -e; echo 'doing some stuff' ( ...
1
vote
2answers
33 views

How to ssh to remote in script without having to provide a password

I am executing the following in my script: ssh pi@192.169.1.89 Which asks me for a password pi@192.169.1.89's password: How do I execute the script to create the ssh connection and then pass the ...
1
vote
0answers
19 views

Interface Choice on Boot Menu [on hold]

I am wanting to have a boot option choice where the user chooses the GUI or the CLI. Not sure how to set it up any suggestions. Thanks
3
votes
1answer
33 views

Iteratively adding value to column of text file

I have a 3 column text file (XYZ coordinates) and I need to iteratively add constants to the first column while appending to the end of the original file. I have tried several options but this is the ...
0
votes
0answers
32 views

Wildcards and Option Flags [on hold]

I have this remove code that deletes files from the system. I need to place option flags and wildcards just like the rm* command. Where will be the best place to put the option flag and wildcard at ...
0
votes
1answer
59 views

Converting multiple commands into a for loop

It gets annoying to retype the commands in the terminal so many times. Basically, instead of just running these commands for ogg_2x2 or ogg_1x1 like in the examples in the image, I need to run these ...
0
votes
0answers
41 views

kill -s SIGINT does not work as expected when launched from init.d script

I want to start some python script (with venv) at startup and monitor the status, for auto restart it if something goes wrong. I've made: - a simple python example prg.py that sleep forever and exit ...
8
votes
4answers
429 views

Bash Read: Reading comma separated list, last element is missed

The output of the command below is weird to me. Why does it not give me back element 5? $ echo '0,1,2,3,4,5' | while read -d, i; do echo $i; done 0 1 2 3 4 I would expect '5' to be returned as well. ...
2
votes
1answer
223 views

How to modify this `while read; mv printf` code to rename only files of certain filetype?

Code in question: ls | cat -n | while read n f; do mv "$f" `printf "video_%03d.mp4" $n`; done The above code will rename all files/folders within the directory executed to: video_001.mp4 video_002....
0
votes
1answer
53 views

Restore function in unix

I have a script to recover files back to their original location. I am missing the options for the script to as "Do you want to recover this file?" Yes or No. How will I implement it into this code ...
5
votes
1answer
118 views

How to pipe multiple results into a command?

I have a piece of code which works, something like this (note this is inside CloudFormation Template for AWS auto deployment): EFS_SERVER_IPS_ARRAY=( $(aws efs describe-mount-targets --file-system-id ...
-1
votes
0answers
33 views

Reverse command insert space at the end of each character

Below is my little bash script that i'm trying to reverse a file. I've been trying tac, awk, sed... but all seem to give me a reverse order but also insert a space at the end of every characters. ...
1
vote
0answers
19 views

How to enable Python automatically after restarting my Centos 6.5 machine?

I am using Software Collections Repository (SCL) to install Python 3 package "rh-python36" on Centos 6 machine. I am adding this script to .sh file located in the /etc/profile.d directory: #!/bin/...
0
votes
4answers
39 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
votes
0answers
21 views

Need to create the UNIX script FTP Files from HAFT to Informatica Server

I have one list file data of that file is list of files present in HAFT server i have to pick the file name and need to login the HAFT server and check the size of file in every 30 sec until file ...
1
vote
1answer
34 views

How to move lines containing specific text to top of file in same order as code executed?

How to move lines containing specific text to top of file in same order as code executed? Here is the code I have: printf 'g?_001\|_002\|_003\|_004\|_005?m0\nwq\n' | ed -s target_file ( credit ...
0
votes
1answer
30 views

Jenkins how to catch error in script

What I am trying to do is once source .... command is executed if there is an error I want to put it into temp file. I tried several ways but no luck. def responseValue = sh(script: """#!/bin/...
1
vote
3answers
70 views

How to move lines containing specific strings to top of file?

How can I move lines containing specific strings (ie. 005, and 007) to the top of the target file? Contents of target file: XXX_008 XXX_001 XXX_002 XXX_009 XXX_003 XXX_006 XXX_005 ----> located ...