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

learn more… | top users | synonyms (2)

0
votes
0answers
23 views

How do i run multiple scripts within another script in the same directory?

Last part of a project and I've created 3 scripts already that do the following, but I now need to run them within a 4th script as if it was one program. Below are the instructions as well as the code ...
2
votes
2answers
109 views

bash source script.sh with exit 0

I use a lot of external files in my scripts. But I have a problem, that if I source a file with exit in the contents of the file, the script exits from loading and the strings that I want to use are ...
1
vote
4answers
179 views

print specific line from multiple files

I have a collection of 5000+ files and I just want to create a output.txt file which contain 27th line of all file along with filename. well I am noob at linux level so what i got from internet is to ...
3
votes
2answers
59 views

use printf to format output of an array

I have an array that contains details about each NIC. Each array index consists of three space-separated values. I would like to have a nice table as output. Is there a way to assign formatting ...
3
votes
1answer
104 views

curl outfile variable not working in bash script

Attempting to shorten a bash script that uses curl to fetch multiple API calls takes something like this: curl --user $USER:$PASS https://api.example.com/foo -o 'foo.json' curl --user $USER:$PASS ...
0
votes
2answers
61 views

How to copy files from directory meeting certain criteria

I'm trying to copy files from directory A to directory B. But I want to copy only files that have lower size then X and don't have file extensions specified in file extension.txt. My main problem ...
0
votes
1answer
28 views

How do I count the number of files in all subdirectories and add the counts together

I am trying to count the number of file in each directory/subdirectory, add them together and get a total which I can then compare to another directory: #!/bin/bash echo "Checking directories for ...
0
votes
1answer
25 views

What are the unreadable characters in Linux Anaconda install script?

The Anaconda for Linux installation scripts contain about 750 lines of a pretty straightforward set of bash commands, but they are then followed with 1.4 million lines of characters unreadable (at ...
-1
votes
0answers
21 views

redirect output of a looped shell script called by nohup

I want to transfer a number of files (in total, hundreds of gigabytes) from remote host using passwordless scp or rsync. The problem is that my connection breaks down easily so I decided to copy one ...
2
votes
2answers
36 views

What's the difference between 'test' and evaluating with /dev/null?

I noticed different .sh scripts for homebrew which check whether it's installed. One uses this syntax: if test ! $(which brew); then The other uses this syntax: if ! which brew > /dev/null; ...
1
vote
1answer
59 views

Prevent shutdown using shell script run at shutdown

Background: I have a Python script that runs (infinitely) from startup in the background of a Ubuntu server. The process is ended by sending a SIGINT which is handled by the script which finishes all ...
3
votes
4answers
133 views

Check if a shell variable has more than one line using built-ins?

I can do this by calling the external utility sed (for a known non-empty $myvar) like so: if [ "$(printf %s "$myvar" | sed -n '$=')" -eq 1 ]; then echo "Your variable has only one line, proceeding" ...
0
votes
0answers
19 views

netcat output does not write to array if launched from cron

I am able to run this script as a user or root with bash or sh. Doing so gives me the output that I expect (arrayFWS is written to file, then emailed). However, when I run it with crontab with user or ...
0
votes
0answers
13 views

Declaring multiple arrays from contents in multiple directories, then iterating over those arrays and their contents [duplicate]

In a bash script, I'm trying to declare 15 separate arrays with the contents of a folder for 15 separate folders (IE; array1 = contents of folder1, array2 = contents of folder 2, ..., array15 = ...
1
vote
0answers
41 views

Bash scripts not found. Maybe EOL issue? [closed]

I am facing a problem that is driving me crazy. In the past months I have been developing a project based on a Linux distribution (Openwrt) that has been recently updated. My project has a lot of bash ...
0
votes
1answer
51 views

How do I calculate the column percentage of a file?

I have a tsv file that contains some values. I want the sum of each column and total number of values and percentage values. Eg: file.tsv contains x 1 1 0 1 x x 1 x ...
5
votes
2answers
277 views

Sed with inplace editing changes group ownership of file

I have shell (php) script that gets in touch with target file this way: inspects whether file and directory are writable with php 's is_writable() (I don't think that this is problem) does in-place ...
1
vote
1answer
46 views

Check if the files in a specific directory have the proper extension?

I have created a script that will create a few directories and then organize other files from one directory by moving them into specific sub-directories based on their extension (i.e. .gif in media, ...
0
votes
1answer
23 views

assign string components into variables [duplicate]

Looking for a smarter way to do something I'm doing already. I have a string: "firstbit.secondbit.thirdbit.fourthbit.fifthbit.sixthbit" The content between the periods changes, but the delimited ...
1
vote
2answers
58 views

bash - All possible combinations of words from different files

I have n files with one word per line file 1 file 2 file 3 ... 1_a 2_a 3_a 1_b 2_b 3_b 1_c 3_c I want to write a bash script that takes all this files ...
1
vote
1answer
27 views

bash set -o errexit problem or the way of incrementing variable?

I have a shell script incrementing a variable like in the example below with set -e: $ var=0; echo $? 0 $ ((var++)); echo $? 1 $ ((var++)); echo $? 0 $ ((var++)); echo $? 0 $ echo $var; echo $? 3 0 $ ...
0
votes
1answer
57 views

How to execute shell script on Kali Linux startup?

I need to execute a shell script on a Kali Linux startup. I am using 2016.1 version of Kali Linux. i tried many things like rc.local, init.d, X11 and GDM3 config etc. but I couldn't get it work. ...
0
votes
2answers
46 views

Get the latest value of an environment variable is a bash shell script

I wonder how can we get the latest value of an environment variable in a bash shell script. Problem I am having is, I have a environment variable which can be changed externally multiple times. But ...
1
vote
1answer
93 views

Automatically enter SSH password without using SSH Key, 'expect', 'sshpass' or Python

I have small device that starts up a tiny VM of PowerPC linux that I need to SSH into from a script on a tiny version of Yocto linux. The PowerPC VM SSH passwords stay the same, but it resets most of ...
0
votes
3answers
36 views

`tcsh` repeat with subshell

I'm trying to figure out how to repeat a complex command inside a repeat in tcsh, like so repeat 9999 (curl http://localhost:80/index.php; echo) I am using a subshell here instead of { and } ...
0
votes
1answer
51 views

List hidden files only (not just dot files) using an ls alias

I would like to use an ls alias (like l.) to output a colored list, consisting of only hidden files & directories, whether or not they begin with a dot. Any suggestions? Example of desired ...
0
votes
2answers
31 views

Sed incremental arithmetic

I want to replace a number at the end of a string by incrementing the number by one each time I run a specific sed line. the string looks like this: server-port=25555 I was thinking I could run ...
1
vote
2answers
48 views

Read files from directory and organize them by extentsion into corresponding folders

I'm trying to create a bash function script that will allow me to create multiple directories with the names below. I'm also trying to organize files by extension into their corresponding folders ...
0
votes
0answers
9 views

runuser error handling

We use runuser inside some of our deployment scripts. In looking at the scripts I'm wondering how the error handling would work if any of the commands within the runuser steps errors out. In ...
0
votes
0answers
20 views

Automated port change

I want to Create a Bash file that a user can execute to change the port a service runs on. Essentially all I have to do is replace a number in a line of text with another number generated by a list. ...
0
votes
1answer
11 views

Filter for remote server response from netcat SMTP scan

I am using netcat to test if remote exchange server (lets call it exchange1) is online with this code. nc -w 3 192.168.130.17 25 I want to create a file that has that servers name if and only if ...
1
vote
1answer
25 views

Problem saving standard output to variable

Looked some for an answer, but not finding anything that sticks out as a solution. I'm trying to make a bash script, and in it I need to save the output of git rev-parse --show-toplevel to a ...
0
votes
2answers
30 views

how to properly log the output of a console program that frequently updates “parts” of the screen, resulting in a messy log file?

I have some Java executable (jar) that is run my some shell script from a cron job once every night. That executable does not print log statements "as usual" just by printing them out in a sequential ...
3
votes
1answer
34 views

Standard/canonical way to test whether foregoing pipeline produced output?

The situation I have in mind has the following structure: % some_command | [PRODUCED OUTPUT] || echo 'no output' >&2 Here [PRODUCED OUTPUT] stands for some as-yet-unspecified testing ...
0
votes
2answers
42 views

How to take the values from two columns in a txt file and match them to values in another

I have two text files formatted as follows: e.g. File1: 900 480 10060.62 2740 -266864.19 3843493.50 2740.00 2740 176.07 900 479 10046.50 2741 ...
0
votes
1answer
50 views

shell script works fine when executed in terminal, but errors out when ran as concurrent program

I'm trying to add the below string manipulation commands in my existing shell script. #!/bin/ksh y=${#text} echo "Length of text: $y" echo "Last _ is in column $((${#text} - ${#end}))" echo "Our ...
0
votes
1answer
59 views

How do I start a background process from a shell script and log the output of the process?

I have a shell script similar to the following: #!/bin/bash # Here is where I set a bunch of environment variables that are # used by the process invoked below... # Now I want to invoke the process ...
0
votes
2answers
42 views

Remove string with > and forward-slash from xml code

I want to remove two strings globally from some xml code. They are: </sellingStatus> and <sellingStatus> I have tried the following unsuccessfully: sed -i 'sed -i ...
3
votes
2answers
129 views

How to extract strings from one file into multiple files

I have a file, xxx.lst with the following data: aaa 111 bbb 222 ccc 333 I need to make 3 files called 111.lst, 222.lst and 333.lst respectively with aaa in 111.lst bbb in 222.lst and ccc in ...
1
vote
0answers
24 views

pmap hangs on OOM process

I did attempt a search, but there doesn't appear to be much out there on pmap so here goes. I have a script that works with WebLogic instances to gather data on them which we can send to our Devs for ...
1
vote
2answers
41 views

Can someone clarify for me about the global variable in this shell script?

Here's the code. #!/bin/bash var_change() { local var1='local 1' echo Inside function: var1 is $var1 : var2 is $var2 var1='changed again' var2='2 changed again' } var1='global 1' var2='global ...
2
votes
2answers
40 views

Efficient Use of dd (buffer many blocks, process one at a time)

Given a file, I need to search for the number of blocks that matches an input block $templateBlock of certain size $blockSize. What is an efficient way to use dd to accomplish this task? The ...
0
votes
2answers
36 views

Command to merge all terminal windows?

Is there a terminal command that merges all open terminal windows into one window with tabs? Been searching all over the place, but have yet to find any solutions.
-1
votes
1answer
31 views

negation equivalence

I have this exercise: Write a script, which uses if-then-else-fi and accept sequence of parameters -a and -b with values "true" and "false", while for every pair writes negation of expression -a ...
0
votes
1answer
19 views

How do you handle multiple validation rules on varied user input?

I'm using a Bash script to prompt users for several variables before continuing. If I want to create static validation rules and execute them on user inputs in an "a la carte" fashion, how would I go ...
0
votes
0answers
41 views

Testing Remote SMTP Server Port

I am currently working in a lab environment to test a script for my production environment. My environment has several remote firewalls, all of which have an external mail Virtual IP (VIP). Our ...
0
votes
1answer
38 views

How to execute a script on SSH Login or device bootup/shutdown? [duplicate]

I have a raspberry pi, which is online and connectable by SSH. What I want to do is create hooks for the following states: When the device starts Before the device shuts down When an SSH login ...
15
votes
3answers
2k views

What does ${1:0:2} mean in this context?

I am looking into the code displayed below and it checks the input if the row/column arguments start with either -r or -c. What does ${1:0:2} mean in this context? rowArgName="-r" colArgName="-c" ...
0
votes
1answer
16 views

Bash redirection in sub (called / spawned) scripts

I'm using apcupsd to respond to events on an APC UPS. The daemon effects responses by chaining BASH scripts. First it calls apccontrol (appending 4 arguments) which in turn calls a script specific to ...
0
votes
2answers
51 views

get day from date with append 0 in 1 to 9 digit

i am using awk command to get creation date of file and from that i m fetching day,month and year but for 1-9 digit i am getting output like 2016041 but i want output 20160401. D=$(ls -ltr $line | ...