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

learn more… | top users | synonyms (2)

0
votes
1answer
26 views

Percent Signs for Shell Vars to Remove Extension [duplicate]

for file in *.pdf ; do newname=${file%\\.\*} done I don't understand how the %\.* is removing the file extension, can someone walk me through it.
1
vote
1answer
48 views

Issue Using Crontab to Create/Restart Screen and Run Command

I want to have a certain script (rails rake task) running on my server at all times - it basically populates my DB using a live feed. I can create a screen (http://linux.die.net/man/1/screen) and run ...
0
votes
1answer
46 views

Parsing string on multiple parts without separator

115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*" I would like to parse the string above. In my case, a string consists of 4 columns (every command has : separator) but it can be much ...
2
votes
3answers
73 views

Help with String manipulation in shell

I was writing a shell script to generate a string in a particular format so that it can be used as a input in one of the XML I am working with. Given a input file in the format <attribute ...
4
votes
4answers
285 views

How can I copy a file in a bash script and rename it while copying and place it in the same directory

How would I copy a file "file.doc" and rename it while copying to "file_copy.doc" and place it in the same directory ? And this only by calling the script and adding the file name in the argument: ...
0
votes
3answers
65 views

How to store the output and print it back again with breaking output into new lines

I want to store the output in a variable and want to be displayed as follows. My code: #!/bin/bash dir=$1 printf "file size: %s\n" \ du "$dir" -hab | sort -n -r |tail -n 2 I want ...
3
votes
2answers
100 views

shell scripting remote commands through ssh

I'm trying to create a shell script which will execute some commands which I require frequently. I made the ssh login to skip the password prompt using a public/private key pair. and after some ...
0
votes
4answers
100 views

Hexadecimal number sequence checker in Linux?

I have a list of hexadecimal number. I would like to check whether they are in sequence or not. That is, they should be consecutive numbers, in increasing order. In other words, there should be an ...
0
votes
0answers
45 views

Shell script to send alert if mount point exceeds 75% [duplicate]

How to write shell script to send an alert if any file-system on server exceeds 75%, in one email notification instead of receiving separate alert email notification for each file-system. I am ...
1
vote
1answer
93 views

what is meant by “^$1” in shell script?

#!/bin/sh #emp3.sh: using if and else # if grep "^$1" /etc/passwd 2>dev/null then echo "pattern found - job over" else echo "pattern not found" fi in the above programme what is "^$1" and ...
1
vote
3answers
152 views

Find records present in file 1 also in both file 2 and file 3

I have three files file1.txt, file2.txt, file3.txt and they are of same format. I want to select records from file1.txt which are present in both file2.txt and file3.txt based on column 2 and column ...
2
votes
2answers
47 views

bash + how to define array variable with instance number

Is it possible to define variable that is called for example machine1 as machine$counter ( while counter=1 ) ? For example, I created the /tmp/config.txt file and set the machine1 as array: $ more ...
0
votes
2answers
53 views

How to match and replace an attribute value inside a tag

I am trying to replace the value of following node using sed command. <KeyValue key="EMPTY_SEARCH_CRITERIA" type="String" value="CS_CODE" comment="Configured empty search criteria."/> I am ...
1
vote
0answers
38 views

Create tree of processes

I'm implementing pstree as an assignment, and I would like to create test tree of processes, but I'm struggling to do so. I tried to do something like this to create tree of background processes ...
1
vote
1answer
32 views

read reading input devided by spaces

How can I read in POSIX bash input like this: <name>,<tag1> <tag2> <tag3>… I tried while read line;do done but this wants newlines, all I have is spaces. (Is IFS solution? ...
1
vote
1answer
48 views

Searching a filename

How to search a file with a given String and currentTimestamp and if not found trigger a mail? For Ex-:I have to search a file whose filename would be like filename_05172015 and trigger a mail if not ...
-1
votes
1answer
57 views

Shell Scripting - return to previous loop until process is completed then die/done

I am writing a bash/shell script to automate some file filtering functions. I am stuck due to being new to scripting and I am not sure how to code the function in it to keep looping the top section of ...
1
vote
1answer
41 views

Assigning ls output to a variable gives unexpected behavior

I was writing a script to clean a text file from a directory (I know,it's a bad idea but I really need it) and I wrote this: #!/bin/bash var=$(ls -p /direcotry/to/file | grep -v /) truncate -s 0 $var ...
3
votes
2answers
82 views

Create a file of pairs from pairs

Say I have the following file: A 1 B 2 CC 33 And I want to create a file containing every combination of two from the previous file, like this: AA 11 AB 12 ACC 133 BA 21 BB 22 BCC 233 CCA 331 CCB ...
1
vote
2answers
140 views

Is there any way to send sms to a mobile number using shell script?

I want to send sms periodically to certain Mobile numbers (Indian mobile numbers.) Is there way I can send with my own cellphone number or by creating account in sites like way2sms , etc. Thanks in ...
0
votes
1answer
50 views

Cannot get interface information using read

The following link has a script to get system information: z3bra' blog Specifically, network() { read lo int1 int2 <<< `ip link | sed -n 's/^[0-9]: \(.*\):.*$/\1/p'` if iwconfig ...
-2
votes
1answer
74 views

How to properly use awk in ksh?

I have: 1 #!/bin/ksh 2 BEGIN { print "START" } 3 { print "Hello World" } 4 END { print "STOP" } 5 6 7 exit 0 then when I try to run the file the following errors appears: ...
1
vote
2answers
94 views

Script to read line by line from a file pipe that to another command and output to another file

I've got this weird old app that I'm trying to support and it stores the passwords in plain text and I'd like to hash them. I'd really like to have an input file in csv with a username,password for ...
2
votes
2answers
57 views

How can I start a file-processing daemon? [closed]

How can I run a script-based tool which will process files continuously downloaded to given directory as they arrive? I'd like to minimize delay (~1 second is OK), script can have own infinite loop. ...
1
vote
1answer
35 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
128 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
60 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
41 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
1answer
73 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
16 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
81 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
50 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
82 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
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
130 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
55 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
48 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
34 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
132 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
48 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
85 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
45 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 ...