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

learn more… | top users | synonyms (2)

0
votes
0answers
11 views

Reload network interfaces without rebooting

I'm doing a BASH script for Arch Linux in a Raspberry Pi 2. The thing is that in some point I'd like to reload the network interfaces without reboot and have my new named network interfaces (en0 and ...
1
vote
2answers
23 views

Best way to make variables local in a source'd bash script?

I have a bash script that generates a report on the progress of some long-running jobs on the machine. Basically, this parent script loops through a list of child scripts (calling them all with ...
1
vote
2answers
23 views

How to number a string in each line of a file

Given file.txt that looks like this: line_ some text line_ some text line_ some text How can I number the lines like this with Bash: line_1 some text line_2 some text line_3 some text Here is my ...
1
vote
2answers
10 views

How to pass an argument from a bash script to 'x-terminal-emulator -e bash -c'?

Let's say I've got this script : x-terminal-emulator -e bash -c 'echo hello > ~/text' I call it foo.sh and make it executable. If I execute this script I'll have a text file in my home folder ...
0
votes
1answer
42 views

What's the most efficient way to log crontab shell script errors with error occurred time?

A common way to log crontab task errors looks like below: 1 */8 * * * sh /pseudo_path/test.sh 2>> my_err_log It's a concise command, but it can't record the error occurred time, and the path ...
0
votes
2answers
29 views

Variable expansion inside parenthesis and quotes

In the script below, I can't seem to make $var1 expand in the second statement. I've tried $var1, ${var1}, echo $var1 and '$var1'. It is inside a few sets of quotes and parenthesis which I guess is ...
3
votes
1answer
21 views

Bash script with conf file with unknown number of sets of variables

I am writing a bash script that has a configuration file. The configuration file will have sets of mode and mtu values. There can be zero or as many sets as the user defines. The bash script will ...
0
votes
0answers
31 views

Drawing a histogram from a bash command output

I have the following output from a miRNA Predictor: Read Sequence:hsa-miR-576-3p MIMAT0004796 (22 nt) Read Sequence:gi|182396|gb|M74088.1|HUMFAPAPC Human APC gene mRNA, complete cds (8972 nt) ...
4
votes
1answer
60 views

How do I find a file name that's exactly 8 levels deep?

I'm using the 'find' command to search for files in a backup system. I want to find all file names containing a certain string (e.g. 'XYZ') that are exactly 8 levels deep. Is there a find syntax that ...
0
votes
1answer
40 views

Print the values from files

I have two files $TMP_RPT_FILE and $TMP_RPT_FILE1 . In $TMP_RPT_FILE - Meter readings come and $TMP_RPT_FILE1 - Meter Id come . I want if any data came in any of those files it should print . I tried ...
0
votes
0answers
29 views

How to scan for wireless networks fast

I have written a script which scans for wifi networks with iw dev wlan0 scan and put the SSIDs in a file. Is there a similar tool wich works a bit faster?
-3
votes
0answers
44 views

Automate Transferring Files from Windows to Unix through SCRIPT [on hold]

I have to make an AUTOMATED shell script which transfers files from Windows to Unix through FTP. I need to do this file transfer process by running a shell script on putty. Currently I am going ...
0
votes
0answers
25 views

Detect when sdcard removed

I'm working with a small Arm board (Emtrion) running Debian Linux. Emtrion has provided an sdcard image that can update the boards flash. I would like to extend the simple update script, so that when ...
2
votes
2answers
47 views

Bash script function that changes the value of a variable

I'd like to make a function for a BASH script that changes the value of one of its arguments, that is a variable. The function that I did is: chck_rgx () { # Checks that the given name for a ...
0
votes
0answers
15 views

Korn Shell script to check if a folder and file exists and print that to a csv file

i am new to unix. I want a Korn Shell script to check if a folder and file exists and print that to a csv file Regards gani
2
votes
1answer
26 views

Dynamic Variable in KornShell Script

This KornShell Script (ksh): envir=Dev eval "${envir}foo=bar" echo "$Devfoo" Output: bar But I will not know what value is assigned to envir variable. So I want to do something like this where ...
3
votes
6answers
354 views

Grep the text which matches with a pattern

I was looking for a command which will print the selected portion of a line which matches the conditions. Eg, my text line is like this: p1=X||p2=Y||p3=X||p4=X||p5=X||p6=Y||p7=X I want to print ...
1
vote
1answer
54 views

Convert multilines to single line with SED

I need additional help, based on similar question I have located here: Convert multilines to single line Current SED example (sed -e'y/)},={/(((((/' \ -e's/-\([^(I]*\)[^0-9]*\([0-9]*\)[( ]*/- \2 ...
1
vote
3answers
83 views

How to pass variables to awk command with conditions?

I have a while loop which reads data from a file with city names: city_name: COIMBATORE MADURAI PONDICHERRY SALEM TRIPUR TIRUCHI TIRUNELVELI TUTUCORIN VELLORE and using an awk command within the ...
1
vote
2answers
247 views

What does [[ -t 1 ]] do?

To my understanding, the script below runs if the user is not root by comparing $EUID and 0. Then, it uses [[ -t 1 ]] to decide if the script is running in a terminal or not. If it is, it will use ...
-1
votes
1answer
59 views

Storing command output into a Variable in Bash

#!/bin/bash NEW_TEXT="if failed Send to Karn Kumarl" OLD_FILE="$(awk '{print $1}' RMANJOBS | while read JB;do autorep -j $JB -q;done | egrep "^/|^insert_job|^description" | sed '0~3 a\\')" ...
-2
votes
1answer
36 views

shell script for easing tasks of System Administrators [on hold]

I am planning to develop a Menu Driven script that would enable a system administrator to perform the daily duties with an ease . For eg. 1. Check and Troubleshoot NTP Issues 2. Check and ...
5
votes
1answer
52 views

Variables outside of while loop

I am trying to echo the variables $f1, $f2, etcetera, outside of the while loop shown below. From what I understand, the scope of the variable is not correct. Therefore I tried a few of the ...
-6
votes
3answers
55 views

Using df -h, i need to create an bash script that displays anything about 60% utilization [on hold]

I need to create an bash script that displays anything about 60% utilization
-3
votes
4answers
73 views

Bash error: missing [: missing `]'

I an writing simple script in Bash, to check Linux file system disk usage on root file system and display a warning message if system is greater than 6%. The commands are running in a terminal, ...
14
votes
1answer
444 views

Why won't function return until background process ends?

Consider this script: #!/bin/bash function start { leafpad & echo $! } PID=$(start) echo "PID is $PID" The script does not continue past its closing brace until the leafpad process ends, ...
3
votes
1answer
50 views

How do you use variables with values containing spaces in a Z-shell (zsh) script command?

I have the following Z-shell script: compiler=clang++ standard=-std=c++11 warnings="-Wall -Wextra -Wpedantic" ${compiler} ${warnings} ${standard} -o ${1} ${1}.cpp This does not work as the ...
1
vote
1answer
24 views

Filesize in for loop

I am trying to get the filesize of each file in a folder by using stat in a for loop. I know why the following is going wrong, but I don't have enough knowledge yet on how to fix this. #!/bin/bash ...
2
votes
4answers
112 views

Convert multilines to single line

I have multiline log file and I want to convert it to single line log. Multiline example: 6/13/2015 12:00:47 AM - { 562} START Web 6/13/2015 12:00:47 AM - Requested Web connection from ...
-1
votes
0answers
16 views

how I will make a generic script which will read .sql files and store the data in some temp file [on hold]

I have couple of .sql file placed in some different Location of server. I want to make a generic script which will read these files and store the output in some file.dynamically if it can create an ...
2
votes
1answer
40 views

How to create gcov files for a project in a different dir?

I want to analyze code coverage datas. I want to create gcov files from OpenSSL (and from other projects), but I can only create them in the same directory of the project, and only for the files in ...
-2
votes
0answers
20 views

Shell Script to check the process id

Currently in the box two users are running Ex-sysddsf ,sysddsu using shell script i need to stop process based on the sysddsu ps aux | grep "Dprocess" | awk '{print $12}' Its showing sysddsf ...
1
vote
0answers
28 views

Shell not exiting (possible reason while loop?) [on hold]

In a project, I have two files makefile, script2.sh. I am only allowed to make changes to makefile. The scenario is like this: makefile calls out script2.sh with specific parameters On basis of ...
2
votes
2answers
111 views

How to check if the parent shell is interactive from a script?

I know that one can use the $- contains i or not or check if $PS1 is empty to tell if a shell is interactive. However, those solutions only work for the current shell. I have a bash script trying to ...
2
votes
2answers
42 views

Delete Entries in File if the Same Entry Exists in a Master File

I have a JSON master config file whose value may be overwritten by a specific account's config file (also in JSON). The Master file has this structure: { "section1Configs": { "setting01": ...
2
votes
2answers
28 views

Shell script - text processing help

I want to create a ldif modify file to update the users on LDAP. I have an input file(alluserdns.ldif) with list of all Dn entries in ldap: dn: cn=testuser2@abc.com, ou=persons,ou=pp,dc=abc,dc=com ...
5
votes
1answer
90 views

Bash script error: integer expression expected

I have a problem with a bash script on raspberry pi: x='gpio -g read 22' if [ $x -ge 1 ] then gpio -g write 23 1 fi The error is integer expression expected. Why?
0
votes
1answer
23 views

Howto prevent service down repeated email sent alerts via bash

I have a simple bash script scheduled to run every 10 minutes, which checks for the PID of any service, and if it is not found, it sends an email alert: #!/bin/bash if pgrep "mysql" > /dev/null ...
2
votes
2answers
40 views

Grouping lines into heterogeneous subsets

I have file with n lines.  (Each line refers to a “question”, and therefore they are labeled Q.1, Q.2, Q.3, ..., Q.n.)  Each line (question) has a “Marks” attribute, which has the value 2, 3, 4, 5, or ...
0
votes
0answers
30 views

Storage allocator out of space error on unix shell script

While running the script called abc.sh, following errors are thrown. abc.sh: line 226: storage allocator out of space on 64946176 byte request ( region 64329285632 segments 1981 busy ...
0
votes
2answers
32 views

BASH script to search for files in folders of 4 digits and older than 7 days

#!/bin/bash unset result result=$(find /home -path "$HOME/TestDir/[0-9][0-9][0-9][0-9]/test*" -mtime -7 -print -delete 2>/dev/null) [ "$result" ] || echo "There are no recovery files older than 7 ...
2
votes
2answers
44 views

find closest matching folder

What is the best way to sort the results of $ find . -name scripts -type d by the occurrences of '/' and then choose the first result. I want to create a function that would cd down to a common ...
0
votes
1answer
26 views

How to create a script to send e-mail by telnet?

I want to create a sh file to send e-mail by telnet. Something like this: read -p "from: " from read -p "from (friendly name): " fromf read -p "dest: " dest read -p "dest (friendly name): " destf ...
1
vote
1answer
25 views

Loop over lines of file, partition file and classify each partition

In the following I've put up my code for iterating over lines of a file in order to collect data within a segment from the file in following fashion: Illustration for understanding procedure: segL ...
0
votes
1answer
39 views

bash script locked at if statement when executed

I am no expert with bash scripting. I am trying to understand why a bash script seems to stop its execution at an if statement. I have added echo statements in the scripts. I have a first batch ...
1
vote
3answers
55 views

Pipe output of one command to two others [duplicate]

I need to pipe the output of one command to two other commands. cat filename.txt | tail -n 1 cat filename.txt | wc -l Since the file is huge I want to avoid reading it twice. I checked tee command ...
6
votes
4answers
282 views

Bash, execute command after invoking a new shell

I am trying to make a script like this: #!/bin/bash sudo -s something... When I execute it, I get a new shell but something is executed only when I exit the shell created by sudo -s, not inside it. ...
0
votes
4answers
90 views

How to extract column name (header) from a CSV file which contains the max value in a row?

I am trying to extract the column name with the maximum value in each row using bash script i.e., the column header value or the value from the same column in the first row. I am using the following ...
0
votes
2answers
24 views

sum of all packets in pcap files

I'm trying to make a simple bash script to calculate packets captured in pcap files, I used tcpdump to get packets in each pcap file and add them using a bash script but it doesnt seem to work. ...
2
votes
2answers
93 views

Merge two-columns files into one file

I have a bunch of files (file1, file2,file3, ...) with two columns. For example, file1 looks like: 0.12 0 0.32 0 0.42 1 0.23 0 and file2 looks like: 0.34 1 0.55 1 0.31 1 0.99 0 I wonder how to ...