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

learn more… | top users | synonyms (2)

1
vote
0answers
12 views

How to dynamically control the audio volume based on current decibels

Since the Internet videos have different sound volume levels I am wondering is there a way to dynamically decrease the audio volume if it's above certain decibels to a normal value. Could someone ...
0
votes
1answer
34 views

error ./c.sh: line 24: [: too many arguments in shell program

I am trying to make a shell script to print the amount of time user was logged into the system but I encountered a too many arguments error. I tried many methods from the internet but none worked. ...
3
votes
6answers
105 views

How to run no more than n parallel subshells

I am trying to run subscripts from a main script, but I want to make sure than no more than n subscripts run at the same time. The following simplified example illustrates. Each subscript creates a ...
1
vote
1answer
53 views

Issue with ':' character in Bash script over SSH

I am currently writing a script that will perform backups on a set of databases, comress them, encrypt them, transfer them to a separate storage machine, and verify that the file made it successfully. ...
2
votes
3answers
135 views

Remove the ^L (aka \f/FF/form-feed/page-break) character

How do I remove the ^L character and the blank lines that come after it on a unix file? I have tried the below and have been able to remove the VT and spaces but am failing to remove the ^L character ...
1
vote
1answer
23 views

How to use SFTP in a script to non-interactively pull file from remote host?

I want to use a shell script to pull a file from another server. I have written a script where i can do this but i want the script to work non-interactively so that it doesn't prompt me for the ...
0
votes
1answer
27 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
40 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
4answers
62 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
12 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 ...
1
vote
2answers
57 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
38 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
32 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
63 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
41 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
31 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
45 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
54 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
17 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
360 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
55 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
85 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
251 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
61 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
38 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
56 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
76 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, ...
16
votes
1answer
463 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
51 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
25 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
17 views

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

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
41 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?) [closed]

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
113 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
29 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
93 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
24 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
31 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 ...