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

learn more… | top users | synonyms (2)

5
votes
3answers
218 views

How to extract URIs from files

How can I extract from a certain number of files all the URIs like magnet: file:? I'd like to have one URI per line as the output. I'd like to use bash to achieve this, but any suggestion is welcome. ...
4
votes
5answers
352 views

Delete the last character of a string using string manipulation in shell script

I would like to delete the last character of a string, I tried this little script : #! /bin/sh t="lkj" t=${t:-2} echo $t but it prints "lkj", what I am doing wrong? Thank you in advance!
3
votes
3answers
147 views

Pipe in a shell script

I have done this little script : #! /bin/sh path="foo" while touch $path ; do path=./${path} done echo "echec avec le nom $path qui fait" echo $path|wc -c echo "caracteres" How can I ...
2
votes
1answer
70 views

SSH config file + shell script help

Well, what I want to do seems a bit convoluted but its the only way I can think of to get the result I want. So here goes. I want to automate ssh to my Pi, in the following fashion: My Pi boots up ...
1
vote
0answers
7 views

Automating minisat solutions

I'm a unix noob and need a simple (bash) script. I am solving SAT instances using minisat. The syntax is minisat inputfile outputfile. However, it only returns one solution. To find all solutions I ...
4
votes
1answer
83 views

Communicating from bash with grunt shell

I'm tired of the slow startup time of hadoop fs just to query HDFS. This isn't a problem with HDFS itself though, because using HDFS file system commands within the Pig "grunt shell" is pretty fast. ...
0
votes
2answers
108 views

If UID=1000 continues, else exit

I am wondering how to implement the following in a bash script. if UID=1000, continue else exit confirm choice (y/n)
0
votes
1answer
41 views

elif [ “$input” = “no” ]; then go the next statement

#!/bin/bash input="" echo "Does a wall needs to be sent?" read input if [ "$input" = "yes" ]; then echo "Sending message to all user about a system reboot or shutdown"|wall elif [ "$input" = ...
0
votes
1answer
52 views

Syntax error in bash script: near unexpected token `else' [closed]

#!/bin/bash input="" echo "Does a wall needs to be sent?" read input if [ $input="yes" ]; then echo "Sending message to all users" echo "" else if [ $input="no"]; then exit fi fi echo ...
3
votes
2answers
49 views

Filtering images according to file name, why?

When filtering the images using the below code, I also need to filter files. For example,IMG_0079.JPG.JPG, when running the code below it's allowing files with additional .JPG to get filtered out, ...
3
votes
3answers
69 views

Moving latest files from one directory to another

I'm trying to move newest files from one directory to another directory. The find command finds the files but not moving them to another directory. The destination directory exists. $ cd ...
2
votes
1answer
96 views

Why does this script work on Ubuntu, and not Debian?

I run a simple minecraft server. I made a script awhile ago for Ubuntu that would automatically create a Gnu screen and start said server. I decided get a new server with debian instead. Now for some ...
3
votes
2answers
34 views

Comparing an string by value of a floating number to a number

I wrote the code below: for j in `cat output_10.txt` do dri=`echo $j |cut -d':' -f1` nu=`echo $j |cut -d':' -f2` tot=`echo $j |cut -d':' -f3` fre=`echo $j |cut -d':' -f4` if [ $fre > 2 ] ...
1
vote
1answer
28 views

How to slice a text file into several files of 100 lines each? [duplicate]

My question might be quite unclear here. I have a giant text file with values that looks like this 0.00601233 0.000139403 0.000133679 0.000139497 0.000141683 0.000141888 0.000138646 0.000133465 ...
3
votes
1answer
50 views

Why does the read command not take interactive options when run by sh?

I want to download a provisioning script that reads some configuration parameters via read, and execute it: curl http://example.com/provisioning.sh | sh The problem is, that the read command in the ...
3
votes
2answers
157 views

using “ifne” in Bash pipe

In my script, I am using the ifne utility from the moreutils package. The line can be simplified to the following: printf "asdf\n" | ifne cat - && echo "stream not empty" ifne only ...
3
votes
2answers
112 views

Can we find page count of a file in Unix/Linux?

I want to count number of pages in the file /var/log/messages, so that I can use pr command to start printing from the page I want to. For example, suppose that /var/log/messages file contains 300 ...
1
vote
0answers
14 views

FFMPEG stream won't show up on Justin.tv

INRES="1366x768" # input resolution OUTRES="1366x768" # Output resolution FPS="35" ...
2
votes
1answer
52 views

Controlling bash script concurrency, flock inheritance

I have a bash deployment script that handles deploying updated code to a Tomcat instance on CentOS, however, both Chef and RunDeck may invoke the script, and since Chef runs periodically there is a ...
2
votes
2answers
37 views

Merging files by rows

Is it possible to copy the whole rows of File1 in a new File3 following the instruction given by File2 by using a simple bash script using sed or awk? File1: /*two or more columns*/ AC 456324 DC ...
2
votes
1answer
110 views

merge csv files by first column

I have 3 csv files like this. csv 1: 1,aaaa,bbb,2014-04-01 2,qwe,rty,2014-04-03 3,zxc,cvb,2014-04-05 csv 2: 2,j,k,2014-04-01 3,a,s,2014-04-04 5,g,h,2014-04-08 csv 3: 2,a,s,d,f,g,2014-04-01 ...
2
votes
1answer
71 views

setenv not working in tcsh

I am trying to install a program on my brand-new CentOs. The installation requires setenv, which apparently does not work, not even in the tcsh shell. Can anyone give me some advice? [Anna@anna ...
1
vote
1answer
73 views

bash: syntax error near unexpected token `('

I am trying to concatenate some files side by side. I use the pr command in the terminal. It works well, but when I use it in a shell script, I get the following error message: syntax error near ...
1
vote
0answers
55 views

Sourcing nested sourced bash script multiple times causes an infinite loop [closed]

I have a cronjob that sources a configuration file, so as to put some variables in the environment, and then runs a script. This config script sources another more general config file that sources ...
3
votes
1answer
19 views

How to execute as the logged-in user in a sudo script (OSX)?

Is there a way to switch contexts like that? The script in my specific case is an installer postinstall script, which requires sudo privileges only for some of the tasks and requires the logged-in ...
0
votes
1answer
46 views

Converting windows date logic into Unix [closed]

I had coded the below logic in Windows batch scripting and I need to replicate the same in Unix. # Calculating Yesterday's Date for /F "tokens=1-4 delims=/- " %%a in ('date/T') do set DY=%%c for ...
1
vote
2answers
73 views

SCP Automation in production environment [duplicate]

I want to implement the use of scp command in a production environment. I don't want to provide my password in the automation script. Is there any way? I need step by step solution.
1
vote
3answers
58 views

what does the -z flag mean here

What does the -z flag mean in the code below: if [ -z $TEST_PARAM ]; then And is there a list of such flags? For a flag like ls -l, I know where to find it, but for a single flag, I didn't get any ...
4
votes
4answers
280 views

what does $* mean in shell [duplicate]

What does $* mean in shell? I have code two function, run_command and run_test, they are called like this: if [ -n "`echo ${GOAT_COMMANDS} | grep $1`" ]; then run_command $* else run_test $* fi ...
2
votes
1answer
43 views

Using xargs with git

I am trying to practice using xargs. I tried the following, passing the SHA1 via xargs: $ git show SHA1 --name-only I also tried: $ git log --author=jim --grep="patch" |head -n 1|cut -d ' ' ...
5
votes
1answer
166 views

ifconfig -a in a shell script

I am writing a shell script to start my network in my virtual machine on boot, since it does not do this right away for some reason with a snapshot of a virtual machine. Since the eth device starts ...
5
votes
2answers
122 views

Is there a way to make this one-liner faster?

Context I have a directory of thousands of zip files that are dated in the form YYYYMMDD_hhmmss.zip and each about 300K. Within each zip file is about 400 xml files each about 3K. The problem I ...
2
votes
2answers
185 views

Store all dates in a given date range into a variable

I want to store all possible dates between two user input dates. The input will be as like 20140605 and 20140830. I want to store every date between the given dates into a variable using a loop so ...
1
vote
4answers
85 views

Extracting a string from fdisk command

I want to write a shell script, which will run fdisk -l and extract a string /dev/sdbn from the output of fdisk -l. Using extracted word I want to mount it to /mnt. For Example: Disk identifier: ...
1
vote
1answer
67 views

Bash Script Display Remote Screen Session to User

I'm kind of new to bash scripting and I'm having trouble figuring out how to accomplish this. I'm working on a script that is designed to backup and manage a java application that runs within a ...
0
votes
1answer
48 views

Using getopts to parse options after a non-option argument

I have a bash script as below in a file nepleaks_upd.sh, that I want to run as ./nepleaks_upd.sh bootstrap --branch off. Couldn't make it to take --branch , but what it works with is ./nepleaks_upd.sh ...
2
votes
2answers
63 views

Removing lines with a single common field

I have a tab separated file that looks like this: 123 some text 123 some different text 334 some other text 341 more text and I want to do two things. One is to order everything numerically ...
4
votes
3answers
201 views

How can I delete a trailing newline in bash?

I'm looking for something that behaves like Perl's chomp. I'm looking for a command that simply prints its input, minus the last character if it's a newline: $ printf "one\ntwo\n" | ...
4
votes
3answers
285 views

Which regular expression methods to validate input could be used in shell scripting?

#!/bin/sh re="\/$" if [ $1 =~ $re ]; then echo "${ATTENTION_PREFIX}$1 DIRECTORY MAY NOT CONTAIN A \"/\" OR LITERAL SLASH!${ATTENTION_POSTFIX}" exit 1 fi Executing sudo file.sh ...
1
vote
2answers
107 views

Email using shell script

Is there a possibility to add multiple e-mails to a single variable so that when the shell script is run, it sends a mail to all the specified emails?
3
votes
1answer
60 views

Using inotify to monitor a directory but not working 100%

I have written a bash script to monitor a particular directory /root/secondfolder/: #!/bin/sh while inotifywait -mr -e close_write "/root/secondfolder/" do echo "close_write" done When I ...
2
votes
1answer
79 views

Accumulate Filename in a Log file using shell script

I have files with their names as ABC_-_123321.20140505_-_161500.CSV ABC_-_654145.20140506_-_135020.CSV String_-_SerialID.Date_-_Time.CSV StartDate, StartTime, EndDate and EndTime are given as ...
0
votes
2answers
128 views

Convert json mapping object to managed csv row using bash script

I have json mapping under properties key as below in a file Customer.json, { "customer": { "properties": { "customerId": { "type": "string", ...
1
vote
1answer
44 views

How to get find -exec to call a shell script?

Taking from the last answer (by im3r3k) here: How do I recursively shred an entire directory tree? I'm trying to get the find command to call a shell script as described. So far I've tried: find ...
0
votes
3answers
66 views

bash script calling itself with different arguments

I just can not get it right. Script takes two arguments, target and command. Valid targets are specified within an array. If target is 'all', script should iterate through all targets. #!/bin/bash # ...
1
vote
2answers
62 views

sh + how to use array in sh script in order to print all values in array

I want to use arrays in my sh script. My target is to create an array with the values a b c and print all values in the array. I succeeded to print each array, but I failed to print all values in ...
2
votes
2answers
128 views

Printing lines with similar text together

I am currently working on analyzing the performance of an application. I've starting by looking at the logs generated by our application and identifying the business logic tasks that are taking more ...
2
votes
1answer
48 views

Displays and their relative position in a shell script

I want to get information about the displays, something like xrandr, but with more info. I want to know their position. So if I have two or more displays connected I want to know how they are ...
2
votes
1answer
38 views

Extracting lines around keys from a file

I have a large file with around 15 million lines. The odd lines contains the keys (but not only the keys) and the even lines are the data. That is, the file is something like: WRTZ Tyrosine ...
2
votes
0answers
42 views

Scripts cannot run simultaneously on startup

I want two scripts (Server_drive, Server_video_boot) running on startup, but there is conflict between them. Specifically, there is always running the script with the lower priority. I tried with many ...