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
8 views

bash + regular excretion + capture java version

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
1answer
10 views

Remote carriage return if there is only one column

A proprietary command similar to "df" returns me this : FOO_vol6 1714236984 1685700840 28536144 98% /root_vdm_10/FOO_vol6 FOO_vol4 253851840 64818424 189033416 26%...
0
votes
1answer
18 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 ln(1), 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
3 views

Running .bsh for 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
15 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
6 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
37 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
43 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 ...
0
votes
2answers
33 views

Unix get last field

I am having a requirement where I need to extract couple of fields from a file with last field. structure of file can be different so cannot hardcode the last field. lets take example of two different ...
1
vote
1answer
26 views

Printing a variable in a file along with some existing columns

I have a long file with three columns. I want to add a column (as the first column) with '5' for the first 200 lines and then '6' for the next 200 lines and so on...
-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
44 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
64 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
24 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
35 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
32 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
31 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
40 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
419 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
222 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
38 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
67 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 ...
-1
votes
0answers
29 views

Unix Removing directories with a function through shell script [closed]

I am trying to create a shell script to mimic the remove command. How will i go about that?
0
votes
1answer
25 views

Find files and specify some to come first in playlist, and the rest in random order?

The following code creates a list of the files in the directory and then shuffles them in a random order then spits out the file in a text document called list.txt find *.EXT | sed 's:\ :\\\ :g' | ...
1
vote
1answer
19 views

wget -i notifying when each file finishes (for processing purposes)

I'd like to be able to process multiple files downloaded by wget -i immediately after they are downloaded (instead of waiting for all files in the list to finish--for the entire wget process to exit). ...
0
votes
1answer
19 views

How can i get alerted when EFS is unmounted fro Linux EC2 instance?

I do not want to use Cloudwatch want to use shell script for this , Could you please suggest? Actually i have written a script as below: But its not alerting me when the EFS is unmounted. #!/bin/...
1
vote
3answers
36 views

read file and based on criterion print desire output

I have input file which looks like this: H1 O1 C1 H2 H3 O2 C2 Br1 I want to have an output file which to have the following output H1 = 1 O1 = 8 C1 = 6 H2 = 1 H3 = 1 O2 = 8 C2 = 6 Br1 = 35 So when ...
0
votes
1answer
27 views

Listen to a folder and modify incoming files on change

I want to convert pcap files to json files using shell script (and tshark). As soon as one or more new pcap files are copied into a folder, the command tshark should be executed and the resulting json ...
0
votes
0answers
44 views

Why install a .deb package with all dependencies fails [on hold]

As in this question and also here I am trying to install wkhtmltox-0.12.1_linux-trusty-amd64.deb. So tried:- wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.1/wkhtmltox-0.12....