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

learn more… | top users | synonyms (2)

0
votes
0answers
6 views

Can the PBS job submission script be changed while queuing

I have prepared a script and submitted to a PBS queue on a cluster. However, I discovered that there's a typo in the script. Could I just modify the script when queuing or I have to qdel first before ...
0
votes
3answers
131 views

How to loop through lines in a file which contains * in each line

I have a file that contains about 800 lines. All the lines contains 1 * character in it. I need to loop through the lines in the file so I used the following simple for loop for i in $(cat ...
0
votes
0answers
56 views

How to detect the user has logged in a domain or local host in the linux shell script?

In the default, the linux doesn't support the domain. But the user can join a domain by applictions, such as: Likewise, Winbind, and so on. For my project, my customers are all enterprise members. For ...
-2
votes
1answer
49 views

Batch Renaming Script [closed]

Edited this question to try and clarify. I'm trying to write a simple renamer script to change files in the current directory 'test1.txt, test2.txt, testcab.txt' etc, to 'edit1.txt edit2.txt ...
1
vote
1answer
24 views

Resend (bounce) a message with attachment in mailx (or any other tools)

I've got a mail folder which contains a unique e-mail containing several attachment. I'd like to script the resending of the email as verbatim as possible. If I write cat tosend | mailx ...
0
votes
3answers
70 views

How to make a single line into two new lines [duplicate]

I want to make a single line into two new lines. My code: #!/bin/bash dir="$1" printf "maximum file size: %s" \ find $dir -printf "%s %p\n" | sort -n | tail -1 with the ...
2
votes
1answer
49 views

Force a job to come in foreground when asked for user input

I'm currently working on an audit-script for a huge platform. In the main-script we use traps and in one of the traps I ask the user for clean up the files. The script has no output in standard ...
1
vote
1answer
35 views

Finding business date within range

Please assist in finding only the business date (Mon-Fri) from the below (in bash) #!/bin/bash startdate=20141030 enddate=20141120 dates=() for (( date="$startdate"; date != enddate; )); do ...
1
vote
4answers
66 views

Comparing files with vimdiff from a script

I'm writing a script to compare two directories recursively and run vimdiff when it finds a difference: #!/bin/bash dir1=${1%/} dir2=${2%/} find "$dir1/" -type f -not -path "$dir1/.git/*" | while ...
5
votes
1answer
133 views

How do I store colored text in a variable and print it with color later?

If I do git status --short, git lists files that are not tracked with two red question marks in front: I'm trying to store this in a variable and print it with color later. Here's my bash script: ...
1
vote
1answer
75 views

Using MPI with a .sh script?

I am a beginner with Unix and MPI. I have a runPR.sh script as below DIR=/directory/buildagain/bin/Project FILELIST=$1 while read FILE do echo "Processing ${FILE}..." ./makeInp.sh ...
0
votes
1answer
83 views

Ubuntu changing shell on me

This Ubuntu machine is showing errors when I start a new terminal. The problem is this: When bash completion is sourced (. /usr/share/bash-completion/bash_completion) the shell taking place is not ...
-2
votes
1answer
123 views

How to find files with the smallest size in a directory

I need to find all files of the smallest size in a directory. My code so far: #!/bin/bash dir="$1" printf "minimum file size: %s\n" du $dir -hab | sort -n -r |tail This code ...
1
vote
2answers
32 views

How to preprocess CUPS' `lp` with a script for a specific printer?

(How) Is it possible to preprocess lp automatically with a script? Piping inbetween (fileToPrint | script.sh | lp -d myPrinter) is no option for me, because I have a lot of source code that does lp ...
-1
votes
1answer
49 views

Getting an error to find directory is empty [duplicate]

I have a requirement that create a script name say ./123.sh when given a path to directory it should print the file or files with minimum, maximum and average file size . eg $> ./123.sh /usr/share ...
0
votes
2answers
86 views

status command doesn't recognise `-p` option in Ubuntu

status -p $pidfile -l $lockfile $prog This command works on CentOS - /bin/sh shell. But when I try to run the same command on Ubuntu 14.04 with /bin/bash shell (or zsh as well), it throws error, ...
1
vote
2answers
46 views

Apply a filter to the value of a variable using backticks

Sorry for asking such a simple question, but reading about this issue on the internet has proven fruitless. I'm trying to better understand the grave/backtick operator and I've been doing okay so far ...
1
vote
1answer
66 views

Combine Bash associative arrays

I am trying make a script that combines arrays on demand. Here is the script: #! /bin/bash declare -A code code=( [H]="h" [E]="e" [L]="l" [P]="p" [M]="m" [E]="e" ) I need to print "help me" - ...
3
votes
1answer
122 views

Copy a file and append a timestamp

I've got two issues with my script that copies files and adds a timestamp to the name. cp -ra /home/bpacheco/Test1 /home/bpacheco/Test2-$(date +"%m-%d-%y-%T") The above adds Test2 as the filename, ...
0
votes
3answers
78 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 ...
2
votes
1answer
51 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
106 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
172 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
47 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 ...
3
votes
4answers
168 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
80 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
26 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
50 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
30 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
46 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
67 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
39 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
67 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
70 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
223 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
480 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
105 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
47 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
39 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
180 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
38 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
109 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
50 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
39 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
212 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
207 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
66 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
32 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. ...