Questions tagged [shell-script]

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

Filter by
Sorted by
Tagged with
0
votes
4answers
73 views

Linux - Find all occurrences of a certain pattern in a line of a file

I have a file in Linux which contains a line like : (memberOf=CN=Group1)(memberOf=CN=Group2)(memberOf=CN=Group3)(memberOf=CN=Group4) My goal is to populate the list of groups that is present in the ...
0
votes
1answer
28 views

How to run commands after SSHpass without closing connection?

I'm learning how to use Linux, and want to see if I can run a set of commands after using SSHpass into a machine. #!/usr/bin/env bash clear virsh start rhel8.4-2server sleep 10 sshpass -p "...
7
votes
1answer
854 views

What does a backslash in front of the delimiter mean in a here document (cat <<\EOF)

I came across the following syntax in a here document not mentioned in bash’s man page cat <<\EOF hello world EOF The man page only mentions quotes around the delimiter and a - in front of it. ...
0
votes
2answers
44 views

Find files with the latest date having multiple pattern [closed]

I have a piece of code like below, where I need to find the latest modified date file of the below mentioned pattern. array=( ($find /path -type f \(-name "REF_DATA*" -0 -name "REF_CUST*...
0
votes
1answer
43 views

how to use find and grep with loop & variables?

I have bunch of files in a directory. # ls -1 file1 file2 file3 file4 file5 file6 file7 file8 file9 file10 Task is to find files older than file5. which I can do like # find . ! -newer file5 ./file1 ....
0
votes
1answer
50 views

Shell script syntax error

I am just starting to learn UNIX and i could not figure the problem here can you please point out the error age=30 if [[ $age -lt 18 ]] then echo "not eligible" elif [[ $age -gt ...
2
votes
3answers
141 views

Is there a way to send all shell script output to both the terminal and a logfile, *plus* any text entered by the user?

I want to send output of a shell script, including user-entered text, to the terminal and a logfile. I thought some combination of tee and exec might do it, but I’ve had no luck so far. I know tee by ...
-1
votes
1answer
139 views

Script n curl POSTs from n lines of txt file & conditionally save output for HTTP request response "200 OK"

Given this cURL "POST" request: $ curl -i -s -k -X $'POST' \ -H $'Host: api.host.it' \ -H $'Content-Length: 205' \ -H $'Sec-Ch-Ua: \"Chromium\";v=\"93\", \" Not;A ...
0
votes
1answer
61 views

Adding multiple user inputs into comma separated line in shell script

I have to get user inputs of multiple domain names until the user is done with inputs. Input can be just one domain name or more than one. and the domain name should be separated by a comma ,. How can ...
-2
votes
1answer
53 views

How to run a command using another command output as part of its text in terminal?

If command1 is: curl -k -v -u user:password https://example.com/v2/image/manifests/tag -H Accept: application/vnd.docker.distribution.manifest.v2+json 2>&1 | grep Docker-Content-Digest | awk '{...
0
votes
1answer
55 views

Full Bash script on creating txt file, directory, copy file, display info

Im still very new to codeing and Im still learning the basics and would love some help with explanation to learn what to do. Im stuck on this matter atm: Bash script to create a file with text inside ...
0
votes
1answer
91 views

-bash:: /bin/bash: bad interpreter: Operation not permitted

I recently replaced adoptopenjdk-13 with adoptopenjdk-16. I have a script file that uses the tool by name, so I changed it from 13 to 16. Its new contents: #!/bin/bash if [ -z ${JAVA_OPTS+x} ] then ...
2
votes
1answer
33 views

unable to expand the variables inside ssh

I'm trying to search for the file of the format : "installation_xx_int_${type}_*log" of the current date inside the remote server using below command: ssh user@hostname 'file=$(find ~ -type ...
0
votes
1answer
53 views

We need to read IP address one by one and then check specific location on that server [closed]

I am having a file ip.txt which contains following details cat ip.txt 10.10.100.11 10.10.100.12 10.10.100.21 10.10.100.22 10.10.100.101 10.10.100.31 10.10.100.32 10.10.100.201 eof if two IP's exist ...
0
votes
1answer
33 views

Add values to an array and loop based on that

I have 3 files like below: CV_REF_DATA_09012021.txt DB_ONLINE_CL_09012021.txt DFR_CL_INS_09012021.txt I want to check if the files are present in /NAS/CFG/ and then add it to an array. It's not ...
2
votes
4answers
1k views

Bash Regex - string should not start and end with a dot

I have a script that takes a string input from users. I am looking to check that the string input should have exactly 2 dots. The relevance is only to the dots. The string should not start and end ...
0
votes
1answer
33 views

Installing WolframEngine on WSL. Shell script won't run

I'm currently trying to install WolframEngine to Ubuntu 20.04.2 LTS which is Linux Subsystem on my Windows computer. This is a ultimately to be able to use wolframscript from within my WSL command ...
1
vote
2answers
123 views

Bash While loop for user input and error prompt with a counter for max tries

I have a while loop created to take user input and repeat the prompt in case of an error. while true; do read -p "Enter hostname : " fqdn pattern="(^[^\.]*\.[^\.]*\.[^\.]...
-1
votes
2answers
53 views

Loop a part of code for multiple variables

I am looking for an approach to build a script. I have 3 files with the below pattern: DailyLoad_Cust.txt DailyLoad_Credit.txt DailyLoad_Account.txt Each of these files has an associated sub_system. ...
0
votes
1answer
57 views

How to safely create file in bash [duplicate]

I have a script that creates a temporary file as a flag to guard against the script being run simultaneously. Currently it uses tempfile, e.g. if ! tempfile -n /tmp/updating > /dev/null; then ...
0
votes
0answers
35 views

How to display who logged in or logged out in last x seconds or minutes?

I am trying to achieve this on bash on Ubuntu 20.04. Any available command?
-1
votes
1answer
90 views

How to restart Plasma 5 from terminal using nohup?

There are a lot of questions and answers about restarting Plasma 5. I realize that using KRunner is the best option, but today I could not access KRunner and had to use a terminal. After reading ...
0
votes
6answers
180 views

sed to replace path to the image

I need to replace path to the image in multiple xhtml files in directory. The files head part is as follows: <?xml version="1.0" encoding="UTF-8"?> <html xml:lang="en-...
2
votes
1answer
118 views

Passing a second variable to gawk in this Bash shell script is failing

I want to pass two variables to my AWK script from my shell script. #!/bin/bash HeaderSize=$(grep -n "# end header data" input.list | tr ":" "\n" | head -n 1) RecordSize=...
0
votes
1answer
112 views

source command is not working inside a shell script

I am literally new to the scripting language. I have to run source ~/.custom_rc command from within a shell script. When I run the shell script, It doesn't show any error. It run just fine. Here is my ...
0
votes
3answers
93 views

Make STDIN executable with shebang

I have a program to list database files. It is called direkly from the shell like db filename to list the whole file, or like db 'filename :: conditions' to list only selected elements ... Another ...
0
votes
1answer
50 views

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

I have a FILE variable in bash which I want replace RT in FILE's value to TTT. Operations: FILE="BlazeRT 123" source_dir=BlazeRT target_dir=BlazeTTT newfile="$(echo ${FILE} | sed -e \&...
0
votes
3answers
43 views

Remove the last rows with no data but just commas from a CSV file through shell script

I am generating a CSV file which ideally should have 1-row or 2-row data but it is coming like 11,ABC,3,4,5,6 ,,,,, I have tried sed and awk commands to remove that empty row but it didn't work out ...
2
votes
3answers
66 views

Find path of original command when overriding it with a shell script?

I'm writing a wrapper script to wrap around the execution of another command; in this case the Chef kitchen command. My script will also be called kitchen and put earlier in $PATH so that running ...
0
votes
1answer
17 views

Synchronizing access to shared, remote resource

I have a shared cache on a remote server that multiple clients are reading and writing to, so I need to synchronize access to this cache. I imagine I could: SSH into the remote and acquire a flock on ...
0
votes
1answer
30 views

Copy data from AWS S3 bucket to Linux SFTP

I am writing bash script to copy data from AWS S3 bucket to Linux SFTP. #!/bin/bash #!/usr/bin/expect set CURRENT_DATE [lindex $argv 0] CURRENT_DATE=`date +"%Y%m%d"` cd /home/ubuntu/test/...
-1
votes
2answers
80 views

How can I start a cpp bin at every reboot?

I am beginner in LINUX operating system and my question is the next one: I have a compiled bin from a C++ source code that uses OpenCV and another libs and it displays on the screen the images ...
2
votes
1answer
88 views

How to concatenate lines of several associated files into one line, and append that to an output file

I have several file named BC**-tmp1.tsv that are the first iteration of a blast output and other file named BC**-tmp2.tsvthat are the second iteration. Example of file BC02-tmp1.tsv (separator : \t) : ...
8
votes
4answers
3k views

Compact way to generate variable with 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

A bash script is using a variable Q for some purpose (outside the scope of this question): Q=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ As this script is used in an environment where each byte counts, this ...
0
votes
2answers
199 views

exec command not found error in Linux

below commands are giving output and exiting the terminal exec sleep 60 exec pwd below commands throws error. please advise on the exec behaviour $ exec test1.sh -bash: exec: test1.sh: not found $ ...
0
votes
1answer
30 views

Bash function can't seem take in directories with spaces in them [duplicate]

I created the following function is ~/.bashrc: function cl {cd $1; echo $1; ls -al $1} (I put the echo command in there just to see what it's actually reading in) In my home directory, I created a ...
0
votes
2answers
43 views

How to check a substring in Bash with single square bracket "["? [duplicate]

I want to detect if the input argument contains some sub-string. I tried below scripts: #1: #!/bin/sh if [ $1 = *abc* ] then echo contains abc else echo not contains abc fi #2: if [ "$...
0
votes
0answers
79 views

start command in linux

I have a custom script which runs on a cPanel server (CentOS 6) which is as below. It starts a service on the specified port which accepts incoming data. It uses start command and runs ok. #!/bin/bash ...
0
votes
0answers
21 views

Custom directory synchronization

I need to make some kind of synchronization between three directories: input directory tree (readonly). working directory tree. output directory tree. Example input directory: drwxrwxr-x 4 - jeusdi ...
0
votes
2answers
39 views

Running a 2nd command as a fallback with the same arguments as the 1st command

I would like to run the following command: tar --sort=name --owner=root:0 --group=root:0 --mtime='UTC 2020-01-01' -cvf api.tar api But need the following fallback for macOS: gtar --sort=name --owner=...
-1
votes
1answer
45 views

Can't run bash: tgetnum: symbol not found

After creating a Docker image I can't run bash, sh and other commands. Today I realize I can't even run the make ( some conditions I can't see now ). This is the error I've got: Making all in data ...
0
votes
1answer
45 views

How to read multiple variables from a file

Example File oj Orange Juice 10 100 A half gallon of orange juice. This is what I did and it worked while read -r simpleName itemName; do read currentQuantity maximumQuantity read ...
1
vote
0answers
68 views

Chicken-egg problem with the shebang line [duplicate]

The first line of any shell script must be the shebang line. The shebang line tells which interpreter should be used to execute the shell script. But it seems there's some logic issue here: If the ...
-1
votes
2answers
66 views

how to parse non-standard Json?

I am using curl to retrieve data. the output is Json output but it's not standard. I tried using jq but i get null output. for example: I want to extract all IDs from this output and store them in ...
0
votes
2answers
88 views

For each directory under path, execute shell script from that directory (when find -execdir is not appropriate)

I have an existing bash script that I call like this: find /path/to/my/stuff -type d -exec sh -c 'cd "$0"; /path/to/my/script.sh function_name fn_parameter' {} \; I frequently change the /...
0
votes
1answer
75 views

How to evaluate bash alias before being passed to bash function?

I have defined a test alias as: alias testalias='python3 -c "f = open(\"/tmp/testopenfile\", \"w+\"); f.write(\"hi\n\")"' It works fine when I run it directly ...
1
vote
1answer
77 views

xdg-open from .desktop file (in script)

I am trying to get a shell script to launch a browser. When run standalone, this script successfully opens a browser with xdg-open http://localhost:8080 However, I am trying to make it convenient ...
0
votes
1answer
53 views

Add multiple options in cmake flag in a shell script and run the shell script

I want to run a set of commands from a bash script. How ever I don't know how to put the quotation in a bash script. The following is the bash script which I want to run, how ever in the cmake -...
0
votes
1answer
61 views

Extract tar.gz file to the same filename

I tried to extract filename1.tar.gz but I got the different name which is the folder archive inside lets say archive_folder; how I can extract the tar.gz with the same name of the filename. I use this ...
0
votes
0answers
17 views

How to tell nmap to give up on target quickly, but not for port scan?

I'm scanning a host: nmap 192.168.0.100 And if that host is down, I don't want nmap to wait for long - I want nmap to give up quickly. So I found --host-timeout in the manpage. However, that ...

1
3 4
5
6 7
296