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

learn more… | top users | synonyms (2)

0
votes
3answers
69 views

Reorder lines in each 3-line record

I have a file which contains lots of records in following manner. Name Address Phone This is the sequence for each record in that file. Now, I want to copy this file to other file with changed ...
1
vote
1answer
32 views

Writing a tab completion script for bash

I made a shell script that reads input from user and kills a process. But in bash if the user presses Tab key then bash suggests some keyword or file names. My script however doesn't suggest anything. ...
1
vote
1answer
60 views

Using sed to replace a string with special chars with another string with special characters

I'm trying to automate switching out a bash prompt for another in .bashrc Original String: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' ...
2
votes
3answers
90 views

variable definition in bash using the local keyword

I'm learning bash scripting and found this on my /usr/share/bash-completion, line 305: local cword words=() What does it do? All tutorials online are just in the format local var=value
-1
votes
2answers
43 views

Processing numbered files via bash

I have a set of files a.rst.1, a.rst.2, ...., a.rst.5000 I need to run this command for each one: ambpdb -p prmtop < a.rst.x > a.pdb.x Where x represents the number for that file. Is there ...
-4
votes
0answers
53 views

Shell script to create users and add them to 2 specific groups

So far, I know the script to add users automatically: #!/bin/bash # Script to add a user to Linux system if [ $(id -u) -eq 0 ]; then read -p "Enter username : " username read -s -p "Enter ...
3
votes
4answers
156 views

how to check directory is empty

I have a requirement, if I execute a script ./123 with an arguments of empty path, say /usr/share/linux-headers-3.16.0-34-generic/.tmp_versions(this directory is empty). It should display "directory ...
-1
votes
2answers
53 views

How to split output lines into multiple lines (only lines not files)? [duplicate]

My requirement is display output lines into mutliple lines My code is: #!/bin/bash dir="$1" echo -n "file size:" du="$(du $dir -hab | sort -n -r | tail -1)" printf "%s\n" "echo "$du"" It's ...
1
vote
1answer
22 views

How create a Init Script LSB Header for this script in Debian?

I have this script below, but how can I create an LSB Header for it in Debian? I want to put in my init.d. I know that for Fedora is ok, but for Debian I don't know. Or where and how I put in ...
0
votes
1answer
45 views

Pass sequence to a bash script

I'm looking for a way to pass an arbitrary sequence of numbers to a bash script. I know about seq. However, the key word here is arbitrary. For example: $ ./do_foo 2,4,5 Should perform something ...
0
votes
1answer
26 views

Ping: Result shows 56(84) instead of what is expected

I'm trying to modify a script to show lost packets as well as ping results. I'm only including the section that isn't working as some of the commands in the script are company specific. for myHost ...
1
vote
1answer
36 views

Cygwin, bash, change an environmental variable?

I have set up a Cygwin environment on my machine (Windows 8.1). pol@pol-lap1 ~/Downloads/software/database/firebird/Firebird-2.5.4.26856-0 $ `set | grep unknown` BASH_VERSINFO=([0]="4" [1]="3" ...
0
votes
3answers
57 views

Removing line-breaks, whitespaces and tabs from every file

Say I have a folder with 10K text files. I would like to remove every space, TAB and linebreak from each file. How can I do this efficiently?
2
votes
1answer
34 views

Clustering identical files ignoring spaces & linebreaks

Consider a folder with many XML files (10K small text files). Some XML files are identical, some are different. I would like to find out what files are identical (ignoring whitespaces, tabs and ...
0
votes
0answers
19 views

Want a bash script for file system monitoring for multiple RHEL servers [duplicate]

I'm trying to prepare a bash script to monitor file system utilization for more than 80% on 20 RHEL 6 servers. Below is the script, #!/bin/bash ADMIN="abcd@zxy.com" ALERT=80 dt=`date '+%a %b %e %I:%M ...
0
votes
2answers
45 views

Bash Script: Parsing a Folder of Text Files Daily without Duplicating Output

HylaFax keeps a history of faxes sent for about a week in its spool folder. I have a script that can go through the files, extract the user and page counts and output it to a log. What's the most ...
0
votes
2answers
62 views

breaking of output into new lines

I created a script ./abc. I want to break the ouput into new lines. mycode: #!/bin/bash dir="$1" echo -n "size of file:" du -hba $dir | sort -n -r | tail -1 my output is: size of files: 20kb ...
1
vote
4answers
183 views

In bash I have to ask for each row from first csv file, second csv file and the answers put to third csv file [closed]

In bash I have to ask for each row from first csv file, second csv file and the answers put to third csv file ... first file. e.g. aaa.csv: aaa bbb aaa aaa ccc fff aaa second file, e.g. bbb.csv: ...
7
votes
5answers
447 views

Storing shell scripts [duplicate]

What is the good common practice to store shell scripts? (bash, sh, ...) For now, I have a few bash and sh scripts in my $HOME directory and I invoke them with $ bash $HOME/script1.bash arg1, arg2, ...
0
votes
2answers
75 views

bash - change filename in a loop

So I have my input directory, output directory and list of files: #!/bin/bash ## shell type dir_in=('/Users/dossa013/data/inland-data/input/') dir_out=('/Volumes/Macintosh HD 2/data/cmip5/cru/') ...
0
votes
2answers
35 views

Help with passing parameters to a file and fetching the credentials

I have developed a shell script which takes schema id and password as parameter to login into database using sqlplus,runs a query and mails the result. Below is the code snippet: #!/bin/sh #Two ...
0
votes
1answer
33 views

Iterating over an array in a shell script

I want to write code that reads a list of packages from an array and tells me whether the corresponding RPM is installed: ARRAY=( pkg-config python python-devel python-libs readline renderproto ...
2
votes
3answers
99 views

add space 5 times at the beginning of each line in a text file

I am looking for a command line or bash script that would add space 5 times before the beginning of each line in a file. for example: abc after adding spaces 5 times abc
-1
votes
1answer
37 views

Loop is not working as it should [closed]

Am i missing something, because this loop sometimes is not working as it should? #!/bin/bash Data="/path/to/data.txt" while true do if [ -f "$Data" ]; then rows=$(tail -n +1 "$Data" | wc ...
0
votes
2answers
51 views

Dealing with if statement

I have enhanced the code from the question I posted before: My code is: DIR="$1" if [ -e "$DIR" ] then echo -n "total directories:" ; find $DIR -type d | wc -l echo -n "total files:" ...
2
votes
1answer
104 views

how to deal with arguments when executing a script

how to deal with arguments when executing a script my code is: #!/bin/bash DIR="$1" if [ DIR eq $1 ] then echo -n "total directories:" ; find $DIR -type d | wc -l echo -n "total files:" ; ...
0
votes
2answers
42 views

Order the output using sed [duplicate]

I need your help using sed. I have this output after executing diff: < #R1#Number = Gauge32: 258 Name = STRING: "TATA" --- > #R1#Number = Gauge32: 280 Name = STRING: "TATA" I need to ...
0
votes
2answers
37 views

displaying output in a single line

How to display output in a sinlge line. My code is: echo "total directories:" && find $DIR -type d | wc -l echo "total files:" && find $DIR -type f | wc -l output displays as ...
2
votes
1answer
135 views

rm -rf: cannot remove `/opt/jetty': Directory not empty

I have a script using the following command to remove a folder: ssh -q root@hostname sh -c 'rm -rf /opt/jetty/' Most of the times it works fine, but occasionally I get this message: rm: cannot ...
0
votes
1answer
71 views

Shell Script Help - Automatically assign users to group

Recently, I have just started to learn linux and I am currently trying to make a shell script that can automate the task of creating user accounts, assigning them passwords and then assigning them to ...
0
votes
3answers
41 views

Loop for snmpwalk in bash

I have an issue in my output using snmpwalk so i'm trying in this script: var=`snmpwalk -v2c -c private ${ip} .1.1.1.6` echo "${hostname}=>${var}" to have this output: R1=>Gauge32: 240 ...
0
votes
2answers
27 views

Using an ASCII file in mailx

I have a ASCII file with Unix user names. How can I mail this list to everyone on the list itself? I do not want to use an alias. I was trying to cat the file to a mailx string but it was not working. ...
0
votes
2answers
35 views

Getting error with sleep and argument in sh script [closed]

I'm doing something like this #!/bin/bash END=3 time_w = 1 for ((i=1;i<=END;i++)); do # do something sleep time_w done but I'm getting sleep: invalid time interval ‘time_w’
0
votes
2answers
47 views

How can I break out of a while loop, from within a nested case statement? [closed]

In the script below - which prompts the user to confirm that they want to proceed with running a potentially bad script - when the user enters Y at the prompt - it will break out of the case block, ...
1
vote
3answers
66 views

Difference between sh -x and ./ for script execution

So I have a simple shell script. What is the difference between the two commands in execution? Is there a preferred way? $sh -x foobar.sh OR $ ./foobar.sh I found the script executed slower when ...
0
votes
1answer
35 views

How to ignore spaces in file path for bash select statement [duplicate]

I have the following Bash Script: #!/bin/bash cd ~/Library/Developer/CoreSimulator/Devices/; files=$(find . -name iaGambro_gambro.sql) select file in $files; do if [ -n "$files" ]; then ...
1
vote
2answers
115 views

How to find maximum and minimum file size along with their path in a directory

I want to find out the maximum, minimum and average file size along with their path. Incase a directory holds similar file sile (say 15kb,15kb) it should display the path of both files and its files ...
3
votes
4answers
139 views

How to maintain a specific number of processes running?

I'm trying to write a shell script for converting a lot of .wav files to .mp3. I use the "find" command to find them, then the "lame" command to convert. I can use a simple for loop for this but I ...
0
votes
2answers
71 views

No of files and directories in a particular directory in shell script

I am working on Linux and it's new to me. I created a shell script countfiledirs. I want to know the number of files and directories in a particular directory. My code is: #!/bin/bash echo "total ...
0
votes
1answer
53 views

How can I populate an array in Bash Shell script loop

cmdline> ls -la /.myScript.sh set index=0 set usrlist[index]="null" while read line do #Total lines read z=`echo $line| wc -l` lines=`expr ...
-1
votes
1answer
59 views

what is shell script? [closed]

Is that some thing like a programming language? Which does provide this option(facility) by a program running on linux or basic program that comes with linux kernel?
0
votes
1answer
62 views

FOR loop not looping

I have the below script that uses 2 for loops. for some reason they loop is not looping #! /bin/ksh CURR_PATH='/main/nedcor/flexcube' cd $CURR_PATH for DIR1 in 'WIP' 'INPUT';do echo $DIR1 ...
3
votes
3answers
89 views

Shell script to move files if certain percentage of lines contain a certain string

I am working on a shell script to move files if certain percentage of the lines contain a certain string. I've got ~2000 files in a directory that each contain a single column of data. The number of ...
2
votes
1answer
65 views

Command for killing specific PID provided by previous command

Sometimes I need to kill a process (the reasons why are not important). And I know I can find that process with the following command: lsof -i :8080, being my candidate the last process in the output ...
5
votes
5answers
331 views

How can I safely get the version of ksh?

How can I safely get the version of ksh from within a ksh script? I have seen the following solutions: ksh --version echo ${.sh.version} echo $KSH_VERSION And if the circumstances are perfect, ...
3
votes
3answers
55 views

Create many files with random content

I am looking for a command to create multiple (thousands of) files containing at least 1KB of random data. For example, Name size file1.01 2K file2.02 3K file3.03 5K ...
0
votes
2answers
49 views

Remove line break in tex file

Remark: I'm working with .tex (TeX) file. In TeX code, line break does not affect the output. To produce a new paragraph we have to use the \par command. Some TeX editors interpret a blank line as ...
-1
votes
2answers
24 views

Shell Script: To extract a part of string from a file after a match is found

A script must be written to extract and return a string value from a file. This must be done only after a match is found in the file for the given pattern. Example: ...
1
vote
1answer
36 views

Passing variables to range patterns in awk

I'm trying to use range patterns in awk: grep -a volume somefile | awk '/^Apr 25 23:44:04*/,/^Apr 26 12:44:01*/ {print}' This works fine, but when I try to execute it by putting the date and time ...
2
votes
1answer
62 views

Filter a log file by month, date and time in bash

I'd like to fetch the data between Apr 24 10:00:00.000000 and Apr 25 24:00:00.999999 in the following log but I am not sure how to get this work: files/file1:Apr 22 02:47:00.663117 somedata ...