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

learn more… | top users | synonyms (2)

3
votes
2answers
71 views

confused with awk and shell variables

I am trying to run a script that uses awk. There is no error it seems, but it doesn't create the file that I want. This is the script: #!/bin/bash echo "Number of domain:" read number echo "Domain ...
3
votes
2answers
50 views

Remove old files in a directory except files present in an exception file

I am writing a shell script to delete old files (older than 60 days) in a directory except few files and these file names are maintained in an exception file present in another directory. I know the ...
0
votes
2answers
43 views

My first Shell that count rows in each file

I'm trying to run a shell script that counts the number of rows in each file, and if the number < 2 I need to move it to a different directory. shell: #!/bin/bash foreach i in (ls *.DAT) a=`...
0
votes
1answer
33 views

Unix command to return maximum float value out of two after subtraction

This is similar to question about getting the minimum/maximum of two numbers, but I'm interested to do the same with float numbers. So basically I'm trying to use shell arithmetic expansion using the ...
0
votes
4answers
68 views

How can I run a command periodically and indefinitely till it's turned off?

I want to run a command every several minutes until I turn it off. After some searching, I found lots of ways of doing the first half (running a command periodically and indefinitely), what about I ...
0
votes
2answers
37 views

bash: Why are () causing error in script but not on the command line?

If I type this on the command line: _longopt () { case "$prev" in --+([-a-z0-9_])) echo foo ;; esac; } it works as expected. If I put it in a script (foo.sh) it ...
-3
votes
1answer
37 views

text to columns in CSV

I am having data in CSV file as follows in single column: Input: Company;C Desc;Region;R Desc; H;Hindustan;13;Maharashtra; I;Unilever;28;Dadra; I would like to change the data Text to Columns with ...
1
vote
4answers
57 views

Replace the second occurrence of a line [closed]

I want to remove all the occurrences of yyyy-mm-dd hh:mm:ss except the first one from the file below. So basically I want very first occurrence of that line to be displayed and I would like all the ...
0
votes
2answers
37 views

browser script (automation)

I want to make Mozilla to run as soon as my pc is on. when Mozilla is open it must be redirected to my internet service provider site and must click on a specific field in that site to enable my login....
3
votes
4answers
138 views

Assigning command to variable without alias

I just accidentally found out that in bash, we can assign a command into a variable without using alias. g=date $g Mon Jun 27 13:00:40 MYT 2016 That works. Here's another example: jj="ping yahoo....
-4
votes
3answers
43 views

Bash - Print lines containing at least all vowels in any order but no consecutives [solved]

The problem is to write a script that takes a file as argument and prints all the lines that contain -at least- all the vowels , -regardless of ordering-, but with [no two same consecutive vowels]. e....
-5
votes
1answer
40 views

Squaring all numbers in a file

Please, can someone share with me, or show me the script for Linux command to read from a file until EOF and compute the square of all numbers read. The result of this computation must be stored in an ...
2
votes
1answer
31 views

Shell script to grab one or many Wistia videos

What would be the best way to come up with a shell script that grabs one or many Wistia videos? There's plenty of proof-of-concepts out there for downloading YouTube videos via a shell script (i.e.: ...
2
votes
1answer
38 views

How to suppress echo of buggy read function

I'm trying to capture a key press in a shell script (e.g. using read) and not to echo it. The three methods I found were stty -echo, the -s switch and stream redirection. However, on macOS, which ...
-2
votes
2answers
59 views

How to compare “abc” with abc in a shell script?

I did not find the answer other location, so seek help here. My code need compare "stop" with stop this is stand bash string. pi@raspberrypi:~/Voice $ ./test.sh | more "stop" stop My code: #!/bin/...
4
votes
2answers
61 views

Compose string of IPs using bash command line

I have a command that returns the following: id1="172" id2="17" id3="136" id4="5" id5="0" /> id1="172" id2="17" id3="128" id4="2" id5="0" /> id1="172" id2="17" id3="128" id4="4" id5="0" />...
2
votes
2answers
45 views

Get only the size of a mounted filesystem

I want to get only the total size of a mounted filesystem. But the catch is that I only know about the mount point. So, I thought of using the df command. To get the size of this mounted filesystem, ...
1
vote
2answers
32 views

Generating strings of words with space delimiters from cut statement

I am new to bash. When I run the following command: grep "type" /root/myFile | cut-d'=' -f2 I get the following: 102 304 503 442 I want to store the contents of the first command into a ...
-1
votes
1answer
48 views

how to write own shell that works with ssh [closed]

I tried several tutorials I modified usermod -s shell path_to_binary username it does not work thru winscp, but works if use from Ubuntu terminal I want to own shell, where I can control over ...
0
votes
0answers
9 views

Setting up SMTP-AUTH & people soft in Postfix

configured SMTP server in people soft -post fix for gmail authentication is not picking up correct sender name- configured in peopesoft- using default sender name as smtp-people soft@org.com this has ...
1
vote
2answers
46 views

GNU Parallel and sshpass with server list in a loop

With this loop we sequential update on all servers (server list = consul members | grep awk {'print $2'} | cut -d ":" -f1) the package consul. for i in $(consul members | grep awk {'print $2'} | cut -...
0
votes
3answers
61 views

How to pick oldest file in a folder from directory [duplicate]

I had n number of files are there in my ../in/ directory. From those files I want the oldest file to process and send it to the ../complete/ directory. The remaining files are sent to the ../error/ ...
1
vote
1answer
49 views

Extracting from Logs

Actual logs are: 2016-06-19 22:08:09 [213917] 1bEgCe-000tZR-E9 ** saadia@aol.com (fahad@manakintextiles.com) <fahad@manakintextiles.com> F=<james@designplus.com> P=<james@designplus....
3
votes
1answer
44 views

Sort files into folders, depending on filetype

I have about 2.8TB (yes, terabytes) of data I have recovered, this will be scanned for duplicates, the machine these files reside on is quite old and only has 2GB of memory (works fine for LVM, ...
3
votes
0answers
76 views

wait bash-builtin burns a CPU at 100 percent

Occurs at least on GNU bash version 4.3.42 x86_64 && GNU bash version 4.3.11 x86_64 I use sleep & wait $! instead of a simple sleep for getting an interruptible sleep by a signal (as ...
1
vote
1answer
53 views

insert the content between the matching pattern in shell script

I want to insert the content between the matching pattern in shell For example : file called input.txt : var a = [ ] file called output.txt : 1152 1185 1185 I want to insert the values ...
3
votes
2answers
170 views

what is $$ in bash? [duplicate]

there is a script I evolved with it, it has line of command like below : mytemp=`echo ${sourcedir}|awk -F/ '{printf "/%s/tmp",$2}'`/`basename $0`-$1.$$ at the last of the command we see $$ that ...
0
votes
1answer
44 views

when i used sed -n ,why this err about sed -n ' $j,4800p' [duplicate]

LINEnum=$(grep -nr "#32" IM_DlCtrlRef.txt | cut -d : -f 1) for j in $LINEnum do echo $j sed -n '$j,4800p' IM_DlCtrlRef.txt >> IM_DlCtrlRef_bak for insertl in {1..4} do ...
1
vote
2answers
52 views

Can I use a shebang to have a file source itself into current bash environment?

I have a growing collection of scripts which should be sourced, not run. At the moment they have the shebang #! /bin/cat but I would prefer the have them be sourced into bash when run, in the same ...
0
votes
1answer
28 views

joint two conditions in bash script

Note: Update Jun 28 I have an iptables script.sh (interpreted by bash) with the rules: function run_ips(){ for ip in $(sed '/#.*/d' ips.txt); do if echo $ip | grep -q "-" >/dev/null; then ...
0
votes
2answers
52 views

Skip catching errors in a shell script

I have a script which compile a program. This program first compiles the source code using configure && make commands, then runs some tests using make test. This script also uses set -e to ...
-1
votes
1answer
55 views

Syntax error at line 18 : `<<' is not matched

Here is my script #!/bin/bash stty intr ^C erase ^H kill ^U p_id=`ps -ef|grep iucmh|grep iuc|grep MSC015|grep START|awk -F" " '{print $2}'` vLogin=`echo "iucmh/iucmh123@4s_MH"` if [ -z "$p_id" ]; ...
2
votes
2answers
45 views

Command behavior is different when executed by an other user (via su -c)

I want to kill every processes who match a specific chain. Here is my script, which works pretty well: echo `ps aux | grep verySpecificChain | grep -v grep | /usr/bin/awk '{ print $2 }'` | xargs kill ...
2
votes
1answer
33 views

shell script echo text name in for looping multiple texts

I am trying to do this text1="word1 word2 word3" text2="word4 word5" text1="word6 word7 word8" for var in $text1 $text2 $text3 do echo $var" in "(__?__) done expected output word1 in text1 ...
0
votes
1answer
55 views

Using multiple sed commands for text manipulation

I have a bash file, in which I would like to make several changes. sed -i 's/ / /g' testfile sed -i -e 's/#[a-z]$//' -e '/^$/d' testfile sed -i 's/ *$//' testfile sed '/##=/ r header' ...
0
votes
2answers
51 views

How to add a column of numbers to a array data file

I have a data file with two columns of numbers: input file 4.182 4.1843 4.184 4.2648 4.2281 4.0819 4.2204 4.1676 4.0482 4.1683 4.0156 4.2895 4.4504 5.2369 4.3776 4.4979 4.3797 4.1372 4....
0
votes
1answer
28 views

How to multiply two columns in a file by a constant number

I have a file like this. input data 4.2394 4.4569 4.2427 4.1011 4.2879 4.1237 4.2106 4.4844 4.2373 4.1071 4.1322 4.0502 4.3103 4.4255 4.4342 4.5262 I need to multiply each element by a constant ...
0
votes
1answer
35 views

Using http remote MD5 hash

I would like to use the md5sums function of pkgbuild without keeping track of new hashsum at each update, and just change the pkgver variable to build a new version of my package. md5 are available ...
0
votes
3answers
78 views

How to do a loop to execute many files

I have a script which function like this for one file. ./script 0001g.log > output for two or more files, like this ./script 0001g.log 0002g.log 0003g.log > output The script take one ...
0
votes
1answer
29 views

Run script simulatneously with loading desktop

I am running Kali 2, and have a script that I want to run on startup. Right now, I have the script in my profile.d directory, but it takes too long to execute. The effect is that after I login, the ...
0
votes
1answer
69 views

cat specific line range from /etc/hosts to dialog box

I need help with dialog box in bash. I like to list, for example all Ethernet switches from /etc/hosts and show them inside dialog box. After that I would like to connect selected switch from the ...
3
votes
2answers
66 views

Can you tell if a file has been renamed?

Many tools out there for syncing files aren't quite right for syncing you're home directory. Because of this, and to learn Ruby, I've been working on my own sync tool. An issue I've encountered, ...
1
vote
2answers
48 views

Defer variable expansion to subshell

My service uses environment variables extensively for configuration (mostly because it's really easy to inject those into a Docker container). I also have some maintenance scripts that I can run ...
2
votes
2answers
68 views

How to refer to multiple files from a directory to one command

I have a command that needs to take multiple input files, which are originally from one directory and have certain file name patterns. For example: In directory /home/mydir/ I have files: A.dat B....
1
vote
0answers
28 views

Avoid starvation using flock with 2 process with write and read lock

I have two scripts let's call them script1 and script2. The script1 is scheduled every 2 minutes and it takes 4 minutes to execute the script2 is scheduled every 30 minutes and it takes 4 minutes to ...
2
votes
1answer
45 views

One of several file-append redirections of “python --version” is repeatably 'overlooked' by bash, but the others aren't [closed]

Why is bash consistently passing one, specific redirected output from python --version to the console rather than appending to file, while every other output is redirected properly? I am developing a ...
1
vote
0answers
27 views

Bash check if firefox use internet

I want to check how much internet use Firefox with a shell script. Here I found good examples to see performances. #!/bin/sh free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*...
0
votes
0answers
26 views

Shell syntax var=${var:-$var2/file} [duplicate]

I came across the following syntax while working with some shell scripts. I am unable to understand what it does and I am not sure what should I search to get right documentation for this var=${var:-$...
25
votes
1answer
2k views

If “bash <file>” works, why is “source <file>” throwing an error?

I have the following script: #!/bin/bash set -x if :; then echo a fi If I run bash /tmp/file, a is echoed, but if I run source /tmp/file, I get: bash: /tmp/test: line 6: syntax error: ...
1
vote
3answers
75 views

Extract filename from another filename

I receive notification files for different files. I want to extract the filename from these notification files which I would use in another process. The first 4 strings of the notification file will ...