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

learn more… | top users | synonyms (2)

0
votes
1answer
19 views

Awk script only works if i edit the text file manually

I'm using awk to organize the information in a text file (It contains CDP neighbors information of a switch taken from terminal) , the file looks like this: Device ID Local Intrfce BIOTERIO Gig 1/0/6 ...
-1
votes
1answer
21 views

Test directory if it contains a set of files based on their extensions

How can I test a directory to see if it contains files typically used for a website? I've searched and found how to test for one extension at a time, which led me to do this: c1=`ls -1 /var/www/*.htm ...
0
votes
0answers
17 views

<text_file.txt>:File or directory not found

I am working on a BASHScript to start wlan monitor mode without interefering with NetworkManager and I am having trouble with this function: serial_setup(){ local file_name=$1 while IFS =, read ...
0
votes
1answer
19 views

A script to convert flac files to wav is not working

I have the following script #!/bin/bash for dir in /home/marius/data/LibriSpeech/train-clean-100/*/* do for file in "$dir"/* do if [[ -f $file ]] then $name=...
0
votes
1answer
14 views

Execute script in new gnome-terminal loading bashrc

I have a script in a gnome-terminal shell and I would like to open a new terminal, load the bashrc configuration, execute a new script and avoid the closure of the new terminal window. I have tried ...
5
votes
1answer
218 views

How to use awk to print only lines containing 5 columns

I have a file which contains pipe delimited data. I want to print the lines which have only 5 columns. I tried the below. It does not work. It simply prints all the lines. Could you please let me know ...
-1
votes
0answers
26 views

Change command before execution [on hold]

Is there any way to edit a command before execution? For example we need to run ls -l So edit 'ls' command before it's execution Now problem is: if we edit the command by following way, the ...
0
votes
0answers
21 views

How to integrate multiple Python/Perl scripts to be executed in one bash script?

I have the following Perl scripts (though this applies to Python and other scripting languages): script1.pl, script2.pl, script3.pl The way these scripts where written, users execute them with input ...
0
votes
2answers
28 views

why will Bash not add my variables together?

I am writing a shell script to calculate the averages of numbers from a file but for some reason bash is not adding my numbers together. I have tried multple ways of formatting the sum='expr $sum + $...
1
vote
1answer
31 views

How to pass a list of variables into sed in a shell function

I want to append multiple variables to the end of a line that contains a certain string. Here is my function: function () { sudo sed -i '/^STRING/ s/$/ '$@'/' FILE; } However I got sed: -e ...
0
votes
1answer
22 views

How can i automatically handle hogging process before system freeze?

First of all hello, and thank you for taking the time to read my question. Update: What my desired outcome with this question is to know the best way to handle a browser process using up all the ...
1
vote
1answer
25 views

Execute a list of commands with checkpointing?

I have a script that does a complicated shutdown and restore procedure. It has some long running commands executed in it. Some take about ten minutes, some are faster. Is there some piece of software ...
0
votes
3answers
23 views

How do I use an If-Else to do certain things if the days of the week are set of days?

I have a requirement that if a day of the week is either Monday, Tuesday or Wednesday , perform certain scripts otherwise I don't do anything. if [[ $(date '+%a') == "Mon" && $(date '+%a') == ...
1
vote
1answer
16 views

How to resize image scan to text content?

I make a script witch scan papers and send it by mail. But in some cases there is a lot of blanc space in the scaned image and I would like to automatically resize image to content. So, for example, ...
0
votes
2answers
46 views

Redirect grep error output inside if conditional

I have written a script to search an .ini file for some specific word. The .ini file has one of two different names, (let's say config.ini or configuration.ini), so I have to check in both. I am ...
0
votes
1answer
41 views

iterate script execution: A call B, B call A

I have a script scriptA.sh that if a variable assume a certain value, it has to execute another script scriptB.sh that execute something and then call a scriptA.sh, that will call a scriptB.sh and so ...
0
votes
0answers
20 views

How to understand the diffrent order of redirections means? [duplicate]

In the Bash Reference Manual: Note that the order of redirections is significant. For example, the command ls > dirlist 2>&1 directs both standard output (file descriptor 1) and ...
5
votes
1answer
277 views

Does bash have different weak quoting rules for special variables?

I don't think I fully understand the nuances of quoting in bash. I have a script, foo.sh, which simply outputs numbered arguments. #!/bin/bash i=1 while [ $i -le $# ] ; do v=$(eval "echo \$$i") ...
0
votes
1answer
30 views

Need help for Linux Bash script

I have bash script #!/bin/sh export DEBIAN_FRONTEND=noninteractive; apt-get update; apt-get -y upgrade; apt-get install -y python-pip python-dev nginx; ##After the command output shows visible ...
0
votes
1answer
17 views

Redirecting the output of a script to the remote server via scp or ssh

I have a script which does ssh to all the servers and shows the output for each execution; can I redirect those outputs to /var/tmp/filename_output.txt on server1? The script runs from server1 to all ...
0
votes
0answers
29 views

Please find the below question for ksh and dot [duplicate]

iN LINUX When we try to execute any script with . it’s being executed and its showing the result. $ . /opt/CA/r11.3/autouser.PC3/autosys.ksh.PC3 $ echo $AUTOSERV PC3 Whereas when we do the same with ...
1
vote
3answers
49 views

Why doesn't the last function executed in a POSIX shell script pipeline retain variable values?

Assume the following script: #!/bin/sh func1() { eval $1'=$(cat)' eval echo "Value$2 inside function : \$$1" } func1 x 1 <<'HEREDOC' Hello World HEREDOC echo "Value1 outside function: $x"...
7
votes
0answers
118 views

What does POSIX require for quoted here documents inside command substitution?

In this question someone reports a problem using a here document with a quoted delimiter word inside $(...) command substitution, where a backslash \ at the end of a line inside the document triggers ...
0
votes
1answer
25 views

requesting to show the critical output as a result

I am having a health check script which run's perfectly, but I want to modify it in such a way that the critical disk should be shown in the output. echo -e " #######################################...
6
votes
7answers
950 views

Replace anything between parentheses even if spanning multiple lines

I would like to use bash or shell script and replace anything between the two parentheses with an empty space. The text between the two parentheses could be in multiple lines, such as: myFunction (...
3
votes
2answers
65 views

Bash assign output/error to variable

I have the following line in my bash file: LIST=$(ssh 192.168.0.22 'ls -1 /web'); The problem I am having is that it is a part of automated script and I often get this on the stdout and not the data ...
1
vote
1answer
21 views

Run process in specific screen window if it exists, otherwise create that screen and then do so

I have little experience with screen, and recently found out that it has windows. Before this, I was just creating a new session for every process I needed to run (I know, right?). However, now that I ...
0
votes
0answers
17 views

Running total after a while loop [duplicate]

I am trying to calculate the running total for RSS and SZ from the "ps -ly" command. I get the total at the last iteration of the while loop but I never get it after while exits. #!/bin/bash ps -ly |...
1
vote
0answers
57 views

How to parse a file for multiple strings? [migrated]

I have a large number of HTML files some of which contain a section starting "<div> specific text" and ending with </div>. I'd like to use a bash script to remove these sections. There ...
3
votes
3answers
62 views

How do I bring HEREDOC text into a shell script variable?

I'm trying to bring HEREDOC text into a shell script variable in a POSIX compliant way. I tried like so: #!/bin/sh NEWLINE=" " read_heredoc2() { while IFS="$NEWLINE" read -r read_heredoc_line; do ...
0
votes
1answer
18 views

bash script error. error on the part of EOF, there must be some files that enter or missing files, anyone can help? thank [on hold]

#!/bin/bash # Info # --- # script can run with the domain as a command line input # `sudo ./nginx_domain.sh my_domain.com` or without and # the script will prompt the user for input #config ...
0
votes
1answer
47 views

Bash script to parse SNMP output

I am working on monitoring a Cisco device where I would need to parse the snmp output and print it in separate more verbose lines. Through the command line I can do this: snmpwalk -m /usr/share/snmp/...
0
votes
0answers
17 views

How to unwind `funcstack`?

It's not a good idea to use set -e inside functions1, because it will cause one's shell to terminate on error. Therefore, in shell functions a lot of my code looks like this: [[ -e $file ]] || { ...
1
vote
0answers
24 views

Need to get the command line of all the daemons that are running

I used the below command to list down all the daemons that are in a machine /sbin/initctl list | awk '{ if ($1 == "tty") print $1" "$2; else print $1; }' Now my next requirement is to get the ...
0
votes
1answer
20 views

Search For Different File Name in Loop

I want to do search through a bunch of directories to find missing files. The format of the directories and files is YYYY/MM/file_name_YYYYMMDD.csv. So what I want to do is something like: for date ...
-3
votes
1answer
30 views

What's wrong with getopts or grep here

#!/bin/bash #return codes: STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 if [ $# -lt 4 ] then echo "UNKNOWN: Please, Pass Enough Parameters" ...
0
votes
1answer
35 views

How does one parse ${!i} (and what does it mean)?

I came across ${!i} in the body of a for-loop of the form for ((i=$#; i>0; i--)); do # ... if <SOME_TEST>; then # ... accumulator="${!i}:${accumulator}" # ... ...
-4
votes
0answers
21 views

How to execute a shell script or unix cammand from a simple html web page [on hold]

I wish to execute a shell script or unix command when button is clicked on my html page in my local machine ? . How do I do this?
0
votes
1answer
30 views

Accuracy of -newer test

It appears that the-newer test is not quite as accurate as I would like. Using ls -lt I get the correct sort order: -rw-r--r--@ 1 p staff 48 Jan 26 14:42 foo.gdb -rw-r--r--@ 1 p staff 328971 ...
-3
votes
0answers
60 views

Process file and do data validation for each column [on hold]

I have file like below: 000679|20161212|+650000123|AUD|123.879 0A0679|20161243|650000123|AD|123879 000555|20161310|+65AA00123|A8D|123.X879 I have to parse the file and do data validation for ...
0
votes
0answers
12 views

convert from win txt. version to linux .sh file an have it autorun after build in suse studio using build scripts

I'm currently using suse studio and I'm trying to use a post build script to convert a windows .txt file to a Linux .sh file and put that as a crontab to run on every boot up. is this the right set ...
1
vote
3answers
50 views

Select the particular range of of fields of a text file

I have a text file filenr.lis contains # 1 2016-05-31-1003-57S._BKSR_003_CM6 # 2 2016-06-01-2255-54S._BKSR_003_CM6 # 3 2016-06-05-1624-57S._BKSR_003_CM6 # 4 2016-06-07-1914-55S._BKSR_003_CM6 ....
0
votes
0answers
20 views

How to get data in correct order from terminal using Expect

I'm using Expect to automatize the following tasks in a switch: log in via telnet ask for neighbors (devices conected directly to the switch) save neighbors information into a text file. Check if ...
0
votes
0answers
34 views

Pass filter into “find” command in bash/shell?

My code look likes the following one: find . \( -name "1" -o -name "2" -o -name "3" ... \) ... There could be a lot of params inside brackets. Is it possible to form a filter list and save it into a ...
-1
votes
0answers
42 views

bash script gives error under Line 11: no file or directory [on hold]

I have a server running with ubuntu,nginx and HHvm. There I have a script wich should delete all Domains from a file. This File is called "Domainsfile.txt" In the same directory where the Domainsfile....
-1
votes
1answer
55 views

Grep a list of words from pairs of files

i have a file with a list of Identifier that i have to grep from another file. I have to do this for a pairs of files (several like 100 pairs). The files look like: A.not.txt.duplicated: ...
1
vote
5answers
56 views

How to replace placeholder strings in document with contents from a file

I have two files, A and B. File A is a letter, as below, which contains several placeholder strings on each line, like <@userid>. <@U39RFF91U> for all the help in this project! Thanks ...
1
vote
1answer
31 views

Generating multiple scripts with different file names

I want to generate a bunch of text files in nano, where each of them contains a script that needs to be run. Everything in the script will be the same, from .sh file to .sh file with the exception ...
4
votes
1answer
45 views

Selecting non-existent files with wildcard/regex

I'm trying to convert hundreds of *.jpg files to *.webp files with libwebp on macOS. Particularly, I want to use the command line tool cwebp to perform the conversion. It works like this: cwebp <...
1
vote
2answers
51 views

Concatenate pairs of files in a loop

I have two lists of files ending with two different extensions and I would like to concatenate them in pairs, in a loop. The file names look like these: These are the files a.ID, b.ID, c.ID, d....