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

learn more… | top users | synonyms (2)

1
vote
1answer
16 views

Create SOX batch script to extract first 15 seconds and rename multiple files in folder

I have a folder with several MP3 files that I need to extract 10-15 seconds of audio from. I would also like to rename these by appending sample-(name).mp3 to the converted files. How can I do this ...
1
vote
1answer
57 views

Run ./script.sh vs bash script.sh - permission denied

When I try to run ./script.sh I got Permission denied but when I run bash script.sh everything is fine. What did I do wrong?
0
votes
2answers
49 views

Create user from bash script

I'm in the process of making a bash script to automate adding a user. My password always have pattern, so I am setting that to a variable then... (this is where I am stuck -encrypting-). I found this ...
1
vote
0answers
34 views

What's in your script Swiss Army knife? [closed]

I've been using Linux pretty heavily that past few months and I want to up my game. But so far my scripts have been focused on speeding up my development time. I'm looking for scripts that will just ...
3
votes
2answers
47 views

Can I change how select options are displayed?

I'm working with select and case in bash. I currently have nine options, which makes a nice, tidy, 3x3 grid of options, but it displays like so: 1) show all elements 4) write to file 7) ...
0
votes
1answer
13 views

makeing a script to change Java SDK

I actually have the script running, but I think it's not very efficient and the only way to get it to take is to run it as "source change-java.sh" Is there a way to get it to not have to output to a ...
3
votes
2answers
68 views

How to use a bash function like a regular command in a pipe chain?

I'm performing several commands on large files from within a bash script. In order to monitor the progress I use the pv command. An example command could look like this cat $IN_FILE | pv -w 20 -s ...
3
votes
3answers
43 views

How can I list every port serving a web page

I have a number of servers, all with various HTTP(S) services accessible on a variety of ports. It's incredibly difficult to keep track of which service is available under which host and what port. ...
0
votes
2answers
52 views

Files greater than 1 GB and older than 6 months

I want to find files which are greater than 1 GB and older than 6 months in entire server. How to write a command for this?
0
votes
0answers
5 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
110 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
43 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
48 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
15 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
61 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
42 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
28 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
39 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
114 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
62 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
77 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
112 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
1answer
18 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
44 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
49 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
36 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
52 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
65 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
68 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
30 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
57 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
89 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
42 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
152 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
52 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
21 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
22 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
35 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
56 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
33 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
40 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
178 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
73 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
34 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
31 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 ...