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

learn more… | top users | synonyms (2)

0
votes
0answers
9 views

How to set up the permissions using the CUPS backend?

I'm trying to write a script that takes command line parameters and parameter order, formats the output from CUPS server backend query, and configure the permissions and locations to install the ...
1
vote
2answers
20 views

Help with iterating fieldA in CSV file, where fieldB has specified value

I've been trying to setup a script to run on gitbash, to process a CSV file so each record that has a specific value, the last field is changed from empty ("") to a value that iterates from 1 to 16. ...
0
votes
0answers
13 views

Copy old cert files and keep the directory path on server

I need to copy old certificate files to new temp directory but keep the directory structure. The certs files are in directories on the server and need to copy all to a temp folder before removing. So ...
0
votes
1answer
35 views

Read line from file, manipulate, and then append to another file

To pool specific content from a batch of files, I do for ID in {92..128}; do sed '3q;d' directory_$ID/stats done Now what if want to put the $ID in front of each line read (preferably shifting ...
1
vote
2answers
24 views

Replace text/string with new line

I have had a requirement where I need to move data to a new line based on a text: Input :61: 456 B66666 :61: 878 N78777 :61: 534533534 BNNN Output :61: 456 B66666 :61: 878 N78777 :61: 534533534 BNNN ...
0
votes
3answers
26 views

How to print loop index to a file using awk?

I'm a new in bash scripting. I need a help in how to print the loop index to a file using awk? Here is the code I used. echo "Write the start and end file number:" read sta end echo "$sta" "$end" for ...
3
votes
1answer
126 views

grep not working in a for loop over a list

I have some log files. And I have a list of user ids. My log files are in a particular format log-yyyy-mm-dd e.g. log-2014-09-30 I am trying to search each userId in the log file. This is what I am ...
0
votes
1answer
30 views

How can I write a script which updates a text file?

I have made this script #PACKAGES.TXT array2=( `find . -type f -iname *t?z|awk '{print $1}'|cut -d / -f 3` ) funzioneZ() { echo -e " PACKAGE NAME: $i " } array3=( `find . -type f -iname *t?z|awk ...
1
vote
3answers
34 views

Remove patterns from string using bash

I'm trying to remove some patterns from a file input string (parsing file line by line). Here is a sample string: 1: (10/17 12:49:31.175) - CONSTANT ID1 - CONSTANT ID2: RAW DATA OUT > ...
1
vote
2answers
29 views

find a specific string pattern from a file in Unix Shell Scripting

I have the below command. unzip -p GLP.K4C.S06F5.BG57218-rdf.zip | grep ":taxonomies-" | head -1 which gives me the output as, <j.2:Taxo_Version ...
1
vote
2answers
43 views

How to find the process with maximum file descriptors?

What is wrong with this for loop? I am trying to find which process has the maximum number of file descriptors. The first command in the for loop ps aux | awk '{print $2}' prints out only the process ...
0
votes
1answer
31 views

Howto adapt this bash construct to a sh valid construct

On converting some bash scripts to a platform where only /bin/sh is available i'm stumble about this bash construct: #!/bin/sh RSTPD=/sbin/rstpd RSTPCTL=/sbin/rstpctl RSTP=0 ...
0
votes
0answers
22 views

Unix Shell script to delete all traces of itself after execution through crontab

My Question has 2 parts. Help with both parts is greatly appreciated. GIVEN INFO: - Lets assume there are 2 Folders, Folder A and Folder B. - Folder A contains many files. - Folder B contains the ...
3
votes
1answer
35 views

Is checking for exit status other than 0 after a `command || return` unreachable?

I am a shell script beginner and found the following patch of code: function some_fun() { #[...] [ -d ${MKAPP_BUILDDIR}/tmp ] || mkdir ${MKAPP_BUILDDIR}/tmp || return 1 if [ $? -ne 0 ]; ...
0
votes
1answer
38 views

how to delete specific characters in a txt file

Please i need some help! I have these lines in a txt file: 1 Q0 /home/nikol123/Downloads/Ergasia_1/Ergasia_1/metadata/13/120411.xml 1 1 Q0 ...
-2
votes
1answer
42 views

How do I automate this in a shell script?

I'm using the application PlexConnect on my home server (a headless OSX box) and I have to ssh in (from an iMac) and manually kill the Python process sometimes with the following: ssh 192.168.0.7 ...
0
votes
0answers
15 views

Shell script to monitor log files going over a certain size [duplicate]

Due to another issue I'm tracking down, one of my app servers occasionally starts generating a large amount of errors and then becomes unresponsive. For now, the simple solution is to restart the ...
2
votes
2answers
171 views

Shell script written in a different shell than what my current shell

If the shell script is #!/bin/sh But the value of my $SHELL is ksh. Will it make a difference if I changed my ksh to sh, and then executed the script. ie. will a script have different behaviour ...
0
votes
0answers
22 views

Move large number of files in a directory into Subdorectories [on hold]

I've had to perform a file recovery operation recently. I've successfully run a recovery program, but it's left me with a single directory of nearly one million files, most of which are fud. I'm ...
0
votes
1answer
31 views

CSH - How to check if input is NOT number

Please help, I can only see forums with this question for Bash, KSH, and others Need to apply it on csh. to check if the inputted $2 is not number nor the word "all" if ($#argv == 2 && ($2 ...
1
vote
3answers
84 views

How to sum match numbers

I'm new at scripting, and need some help. Will appreciate your answers. I got this assignment, which is to find the sum of all five-digit numbers (in the range 10000 - 99999) containing exactly two ...
0
votes
1answer
48 views

reading file using for, while - behavior

Consider the below scenario 2 vms - 192.168.229.131, 192.168.229.132 Both the vms has it's ip as 192.168.229.151 & 192.168.229.152 in it's /etc/hosts file Say there are around 50 vms like i ...
0
votes
1answer
34 views

Please help me to debug this notify-send battery alert script

I used crontab -e to define the following: */5 * * * * env DISPLAY=:0 /home/max/.bin/battery-check.sh The contents of the script are: #!/bin/bash ...
1
vote
1answer
72 views

Running commands after ampersand symbol & in a remote ssh session

I have a shell script that initiates a long, resource-intensive command on several different machines. In order to execute the script on each machine in parallel, I have an ampersand symbol after ...
2
votes
2answers
41 views

Optional arguments after or before the mandatory arguments?

I'm creating a shell script and I need it to take two mandatory arguments and one optional. How do I check that? In most scripts I've seen, the optional arguments are passed before the mandatory ones, ...
-3
votes
0answers
19 views

Bash Script for checking if an Oracle DB is UP or Not? [closed]

Any shell script for checking the oracle DB is up or not !!! apart from nagios plugins available?
0
votes
1answer
31 views

How to use commands on files that start with “-” [duplicate]

I'm having trouble using using commands on files that start with "-" (i.e. -file 1, -file 2). It is giving me invalid option errors. For example: cp '-file 1' '-file 2' However, echo still works. ...
1
vote
1answer
19 views

To print execution time of Script from Script?

I'm searching PDF files in all directories except those in .texpadtmp by code originally based on this discussion. function findpdfs() { find . -iname '*.pdf' -not -path "*.texpadtmp*" | while read ...
2
votes
1answer
27 views

Why am I getting “too many arguments”

Here's a part of my script that is telling me that I have too many arguments on line 3: #!/bin/bash export LC_ALL='C' if [ `echo "*file 2" | grep -o ^.` = '.' ] then echo success fi Anybody ...
2
votes
1answer
26 views

date command, going back one or two days. Seeing different flags

I'm writing a bash script that should run on OSX and Ubuntu. I'm not sure if this particular problem is due to an OS mismatch; more likely it's a difference in the date command on the two shells, ...
0
votes
1answer
47 views

Bash error: “[y command not found” [duplicate]

I am trying to get this script to function correctly but I get ./passmark.sh line 7: [y command not found. Here is my script #!/bin/bash # A simple script to ask a user for a pass mark and then ...
0
votes
1answer
55 views

How to update specific row and column using awk? [closed]

I have the index file as below balsum|3|8|13|24|07:29:29|1111989 smaval|6|11|16|16|20:21:19|2565 paycan|3|8|13|3149|07:24:36|2930 format: alrt_type|index1|index2|index3|value1|value2|value3 ...
1
vote
1answer
39 views

count matches and mismatches group by

Please help with a shell script of the following. I need count number of consistent variables in each lane (col1) across samples (col2). For example, since all the values (col4) of lane1 variable 1 ...
0
votes
2answers
113 views

proper way to iterate through contents in a directory [duplicate]

I need to iterate through every file inside a directory. One common way I saw was using the for loop that begins with for file in *; do. However, I realized that it does not include hidden files ...
1
vote
1answer
31 views

How can I maintain line breaks in body text with mailx when sending attachments?

I have a script that emails the text of a log file as the body of the email. That log file has some blank lines between lines of text for readability. When I use the following line in the script, ...
47
votes
2answers
3k views

Shebang starting with `//`?

I'm confused about following script (hello.go). //usr/bin/env go run $0 $@ ; exit package main import "fmt" func main() { fmt.Printf("hello, world\n") } It can execute. (on MacOS X 10.9.5) $ ...
1
vote
1answer
31 views

Apt-get failing in bash script?

I have several machines (running Ubuntu LTS 12.4 64-bit) which need to be configured in the same way, so I created a shell script which will run automatically the first time the machine boots. It ...
-1
votes
1answer
25 views

What is the easiest way to count the amount of letters in a string entered

I am currently writing a program in the raspberry pi that will allow a user to enter a string, and have the program count the amount of letters in it. I am looking into expr but I don't know how to ...
1
vote
1answer
34 views

How can I run a script recursively in a directory

I am using the following code to decode JPEG-compressed DICOMs. find ./* -maxdepth 0 -name '*.dcm' -printf 'dcmdjpeg %p %p \n' | sh I run this code inside any folder containing those files. The ...
10
votes
6answers
355 views

How to extract a key value pair from ps command

I am trying to extract application name from ps command: ps -af -u sas |grep "java"| grep -v "grep" above command produces the following: sas 24431 1 0 Oct10 ? 00:51:08 ...
0
votes
1answer
31 views

How to replace symbol || with |“”| using sed

I have a file that uses | as a delimiter. Some of the records have empty cell as || (nothing inside). I am trying to replace them with |""| with following sed command: sed -i 's/\|\|/\|""|/g' file ...
0
votes
1answer
41 views

Null message body; hope that's ok

I have the following command below as part of a cronjob. When I run the command via cron or at the command line, I get Null message body; hope that's ok. The contents of the email are empty but when ...
1
vote
2answers
39 views

Append a file, output to screen and redirect from stderr all at once, without tee

I'm running a time dd command in a shell script, and I'd like to output the results to a file, and print it out on the screen. The line that I'm currently running is: (time dd of=$dest_filepath ...
0
votes
1answer
26 views

evaluating a string in csh

script1 is as follows #!/bin/csh echo $* $* Then I run the following on command line: >script1 setenv VAR "/user/path" \; ls It gives output as: setenv VAR /user/path ; ls setenv: Too many ...
5
votes
3answers
163 views

Use bash's read builtin without a while loop

I'm used to bash's builtin read function in while loops, e.g.: echo "0 1 1 1 1 2 2 3" |\ while read A B; do echo $A + $B | bc; done I've been working on some make project, and ...
4
votes
2answers
176 views

Run script in a screen

I want to run a bash script in a detached screen. The script calls a program a few times, each of which takes too long to wait. My first thought was to simply open a screen and then call the script, ...
0
votes
1answer
39 views

SSH over multiple server and save output of multiple commands in file on local server

I want to SSH over multiple server (host 1, host2 and host 3) and save output of multiple commands (cmd1, cmd2 etc) in file (output.properties) on local server. I know there are a few posts similar to ...
1
vote
2answers
31 views

Expect script: How to handle two processes?

I am using Expect to automate VoIP calls for quality measurements. My script is calling another VoIP client for a given amount of times. Before the calls should be handled, tcpdump should sniff all ...
0
votes
1answer
28 views

Another unterminated 's' command

I am trying to make a simple replacement for an IPv4 address script. sed "s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/192.100.100.100/g" This is what I have. As stated in the title I ...
4
votes
4answers
271 views

extract every nth character from a string

I am trying to figure out a solution for this question. My approach to this problem so far is as below. Append all the characters together to make it a long string. After the above step, remove ...