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

learn more… | top users | synonyms (2)

0
votes
3answers
20 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
32 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
59 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
233 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
41 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
30 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
48 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
52 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
67 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, ...
11
votes
1answer
414 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
49 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
23 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
107 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
15 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
26 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
23 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
106 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
26 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
87 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
22 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
27 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
31 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
32 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 an alias that would cd down to a common folder ...
0
votes
1answer
23 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
38 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
54 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
266 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
83 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
86 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 ...
0
votes
1answer
43 views

Save command string into bash variable

I'm running a command like so, with the $OUTPUT variable saving the results of the command. But I also want to save the command itself to a variable for inclusion in a status email. OUTPUT=$(php -f ...
0
votes
1answer
23 views

Loop commands to network daemon?

I'd like to feed a network daemon using a loop! To be more specific: There is a network daemon listening on localhost:portx. The daemon expects me to guess a PIN between 0000 - 9999. I want to use ...
-1
votes
2answers
35 views

Create shell script to remove certain files from specified directories

I am looking to create a simple script that does the following: cd /specified/directory cd into child directory only if it has a 4 digit name e.g 1234 rm -r all files that begin with letter P rm -r ...
0
votes
1answer
49 views

Bash script strange behavior - script does not act as manual commands

So, this is strange. When I manually run commands it all works fine, but when I run a script with identical commands, I get strange error output. This is what I run: lxc list; for elem in ...
2
votes
0answers
29 views

Sed is unable to copy temporary file to original file [duplicate]

My aim is to edit the file(Whose owner is user1) using script where user2 don't have permission to directly edit the file but it should be edited when executed through script by user2, so I set SUID ...
-1
votes
1answer
38 views

How to rename or delete an alias permanently from system?

I have created one alias in my system, printf "%s\n" "alias shh='sqlplus hfdora/hfdora@hfd2" >> ~/.kshrc Now, I want to change the alias name from shh2 to shh Also, how to delete other ...
2
votes
2answers
28 views

Call a script for another script, but don't exit the parent if the child calls exit

first.sh: #! /bin/ksh echo "prova" . ./second.sh echo "ho lanciato il secondo" . ./third.sh echo "ho lanciato il terzo" second.sh: echo "sono nel secondo script" dosomething1 exit $? If ...
3
votes
4answers
377 views

Add path to $PATH if not already in $PATH [duplicate]

I need to add a path in a bash script, but it may be executed several times: export PATH=${OPENSHIFT_HOMEDIR}/app-root/runtime/bin/:${PATH} I don't want that path to be added over and over. How can ...
0
votes
1answer
43 views

sftp to use password stored in a parameter file

Is it possible to to connect two server through sftp with a batch of commands and where the authenticating password needs to be read from a file(where it is stored previously).I am new in UNIX world , ...
1
vote
2answers
47 views

Returning an variable from a function

I have the Linux script from bellow. I can get to return from the method decrypt nothing in order to unzip a file. The method decrypt sends a string with the name of a zip file. Please give some ...
1
vote
3answers
42 views

How can I un-write protect file made by tee?

I have a small program and I want to ensure that it works on both write protected files and un-write protected files. So, instead of using echo $text > $file or echo $text >> $file, I am ...
-8
votes
1answer
58 views

replace the the first line of all .sh files in a folder

Create list of all .sh files in current folder. Check first line of each file in this list and if file starts with #!/bin/sh then replace that with #!/bin/bash. Only modify files that have #!/bin/sh, ...
-5
votes
1answer
61 views

Find the number of files with sizes

Find the number of files with sizes > 100KB in /, /bin, /usr, /usr/bin and /usr/sbin directories and output them in a two column format with the name of the directory and the number of files.
1
vote
3answers
40 views

permissions of script to change permissions?

I have a VMWare VM that directly accesses some disks. In order to run (without running vmware as su which has its own problems) I need to change the ownership of the devices. I've done this manually ...
0
votes
0answers
4 views

Find MAPISend syntax and Replace with BLAT syntax

My MAPISend code seems to have kicked the bucket so now I am trying to replace over 1,500 MAPISend lines with BLAT. Is there a way to search through my scripts and find the MAPISend syntax: ...
2
votes
2answers
37 views

Embed “cat file” in CURL data

I would like to cat the contents of a file.txt and use this as part of the --data field in my curl query. I tried: curl ... --data '{ "file_content":[" $(cat file.txt) ", ...]}"' ... but that ...