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

learn more… | top users | synonyms (2)

3
votes
4answers
94 views

How do I extract a long listing field?

I want to extract the access day of a file in a shell script. I tried by writing the following script but it doesn't work. When I echo accessday, the output is "staff". file=$1 accessday=$(ls -lu ...
2
votes
1answer
29 views

Xdialog - Capture user and password for a shellscript

I'm trying to create a simple "User and Password" GUI input for a shellscript, with the --2inputbox parameter for the Xdialog command: While following the documentation seems to be easy, it does ...
0
votes
1answer
35 views

How to set multiple env variables from stdout pipe

I have a bunch of piped shell commands that give some env output. I want to set these as env variables for an additional command to add to the chain Kevins-MBP:ops kevzettler$ eb printenv | tail -n ...
0
votes
1answer
55 views

bash script to replace server short names in a file with fqdn

I have a rather large config file that has server short names in it like this: [host 1] host = server1 [host 2] host = server2 [host 3] host = server3 I need to replace all the server short names ...
1
vote
1answer
42 views

Executing shell script from command line [duplicate]

I have a perl script that converts a file to json format and writes the output to a separate directory. It accepts 2 parameters, filename and output directory. The script needs to be run on multiple ...
0
votes
3answers
45 views

How to test which strings from File A are not present in File B, without displaying anything that is present in File B and not in File A?

I have a text file, say sitelist1.txt (File A), that has some URLs like below: http://www.facebook.com http://www.twitter.com http://myspace.com/profile http://orkut.com/archived I have another ...
1
vote
1answer
24 views

Which shells have functions where “local” does not alter exported variables for child processes?

In the example below, an exported variable is re-set as local in a function. Bash, Zsh, Fish don't pass on the original value to the child process. Are there any shells that make local affect the ...
0
votes
2answers
53 views

Problem with grep -o

I have a text file as shown below. 192.168.10.1 192.168.45.45 192.168.255.255 192.168.0.5 Random text comes here 8.8.8.8 224.23.25.12 225.1.2.3 226.0.0.0 ...
1
vote
2answers
44 views

Is it possible to declare a local variable without overriding the original for the child processes?

If I have a pre-existing ENV variable, is it possible to declare a new local variable with the child process using the original value? Keep in mind, I don't know which variables the child process ...
1
vote
1answer
34 views

What's the correct location to install a bunch of scripts & support files for a program?

I have a project that comprises a bunch of different files (listed below). I'm creating an install script for it, and want to make sure they all go in the right place from a unix hierarchy ...
1
vote
1answer
27 views

how to pass a mixture of arguments to a script and only of them optional -argument

I've been exploring this issue for longer than it should take me and finding getopts a very confusing tool. All I want to do is the following. Have a script that I can pass arguments like this $1 $2 ...
0
votes
1answer
28 views

Bash script to change password in chroot

I have build a Linux From Scratch live CD and wrote an installer script for it. There is a step in that script in which I take an username and password from the user and create an user. The installed ...
1
vote
4answers
82 views

How to break a long string into multiple lines in the prompt of read -p within the source code?

I am writing an installation script that will be run as /bin/sh. There is a line prompting for a file: read -p "goat can try change directory if cd fails to do so. Would you like to add this ...
0
votes
1answer
41 views

Unexpected EOF while looking for matching ' " '

I'm trying to configure hadoop using cygwin.. It is my first time to use unix environment but while configuring hadoop-env.sh i get the this EOF error # Licensed to the Apache Software Foundation ...
1
vote
2answers
138 views

Add date to name of the folder created using mkdir

I have a script which when executed will produce some files. I modified the script by adding the following two lines at its top mkdir ABC cd ABC So that the formed new files will be inside the ...
1
vote
1answer
35 views

Bash: How to get a value from an array to create command from it

Is it possible to use bash to fetch a string from an array provided in the following syntax within a config file? | | Version | PackageManager | Webserver | Database | ...
0
votes
3answers
42 views

Infinite while loop issue using read

I am writing a small script that asks a user to insert a number from 1-10. The script will then tell the user if the number is between the requested values, and continue from there. However, I am ...
0
votes
1answer
37 views

Install Linux From Live CD

I have made a Linux From Scratch and built a live CD from it. I also wrote a script in /usr/sbin named install-lfs. When I want to install Linux, I just have to open a terminal in the live session and ...
0
votes
1answer
41 views

reminder script to remove string from file

I am newbie to scripting. I have debian squeeze installed on my box. I have BIRD daemon to route traffic of particular IP. We add IP to bird-route.conf automatically from ruby script if traffic spikes ...
0
votes
1answer
22 views

Output NamingVariable for Multiple Files in Bash Script

I have a script I've created that will pad a series of Jpgs, create a subdirectory in the working directory, move the padded Jpgs to the subdirectory, change to the subdirectory, and then use ...
2
votes
1answer
43 views

find and replace a string in a file without using temp file with SED

I have a text file called sample.text which looks like this Continent Lat/Lon: 46.07305 / -100.546 Country Lat/Lon: 38 / -98 City Lat/Lon:(37.3845) / (-122.0881) I want to process this text to get ...
0
votes
1answer
43 views

How do I get the time when the system booted up in epoch format?

I need to write a script that figures out if a reboot has occurred after an RPM has been installed. It is pretty easy to get the epoch time for when the RPM was installed: rpm -q --queryformat ...
1
vote
2answers
64 views

Bash script - chomp parts out of a line

I have a data file (see sample three lines below) separated by pipes. What I want to be able to do is to "chomp" out the fields and put them into variables. They are of pre-defined lengths. I want to ...
1
vote
0answers
34 views

Find list items in other file [duplicate]

I have one file with hundreds of unique IP addresses (each on a separate line) from which a bot tries to login to one of our services. I would like to see which of these addresses appear in another ...
0
votes
1answer
51 views

Shell script - creating and assign to groups advice needed on my script

Where could I include man useradd and -g and G i'm not sure where to include these commands above. The current shell script doesn't successly create the user but does run. #!/usr/bin/env bash ...
4
votes
1answer
52 views

What is the sort order when using conditional operators?

I wrote a bash script that processes a list of filenames (using glob expansion, as in for f in *) and then outputs a subset of this list to a file. Subsequently I read the content of this file into an ...
-1
votes
1answer
59 views

Remove files with certain extensions and 0-length files

Want to know how we can clean the directory by removing all the files with a zero length , with a .tmp or with a .swp extension that found in this directory (note that sometimes .swp and .tmp files ...
1
vote
0answers
35 views

What is the difference between #!/bin/bash and #!/usr/bin/env bash [duplicate]

What is the difference between #!/bin/bash and #!/usr/bin/env bash? Thanks in advance, Liam.
4
votes
2answers
77 views

Syntax error unexpected end of file [closed]

I have written a shell script which allows me to create a user and assign them to a group but I keep getting the error line 19: syntax error: unexpected end to file What am I doing wrong? Would it ...
0
votes
0answers
26 views

Possible improvements to script that runs golismero security scan crash-safe?

I am trying to do it this way. Due to some issues with golismero that causes more crashes then I'd prefer, I use a workaround suggested by the dev team and saves all found items to the db - and if it ...
0
votes
2answers
65 views

How to search whether more than one lines exist after a certain string?

I have a script that generates following output: URL: http://framework.com Name(s): Patching Framework ---------------------------------------------------------- URL: http://asjkdfhn.com ...
0
votes
1answer
66 views

Running commands from root directory of new workspace

I have a shell script that cd's to a specific directory to run a set of python files. Now that I have this committed to source code management(the script and the python files) I am cloning this into a ...
4
votes
3answers
103 views

Insert text at specific line number

I'm working on a bash script that will split the contents of a text document depending on the data in the line. If the contents of the original file were along the lines of 01 line 01 line 02 line ...
1
vote
4answers
102 views

Bash: How to print additional column matching IP Address to Name

I'm using netstat to collect information about connected IP's. And I have the following format: netstat -tn 2>/dev/null | awk '/:80 / {print $5}' | sed 's/.*::ffff://' | sed 's/:.*//' | sor t | ...
1
vote
1answer
32 views

How to get current working directory before changing it

I have this function snip-git(){ cd ${snippetdir} git add . git commit -m "." git push -u } When git finishes pushing the changes, I want to get back to the directory I was when I ...
-8
votes
2answers
52 views

Build a Renaming Script [closed]

write a script that will check each folder/directory and rename the folder title if it contains the word “section.” The folder should be renamed to use the word “chapter” instead of “section”;Your ...
0
votes
1answer
27 views

How lsof attach to shell script PID?

I am trying to run a small shell script .sh and i wanted to see what files it's going to open using lsof. how do i execute shell script and attach its PID to lsof? I tried following but didn't work: ...
0
votes
0answers
27 views

Preventing Termination of Script on Error

The script below is used to parse thousands of files which are located in multiple directories. However, some of xml files which need to be parsed have errors files. The script below terminates in the ...
3
votes
3answers
46 views

Is .zshrc read on X session open? / How to execute a script on X session open?

I have a custom command I need to execute on X session open (mouse config). I made a script out of it, now I'd like to make sure it gets executed on session open. There are distribution-dependent ...
1
vote
2answers
80 views

Find files containing a set of words

I'm using grep to find files within a directory, containing a set of words. But grep search lines containing these words, what I want is grep to show me the files or file containing all those words ...
0
votes
1answer
57 views

How not to proceed to the next elif if the first is true?

I have a list of text files in a directory which I want to search from terminal. To not make myself think too much, I want to be able to search for few words, example search one two three if there is ...
0
votes
2answers
46 views

If-Else Statement not working - syntax error near unexpected token 'fi'

I'm starting to write a script that is solely a file manager, and I am setting a function asking the user to set their preferred text editor, and it always ends with an error message: ...
1
vote
3answers
166 views

shell scripting with large amount of files - timelapse

I have created a shell script to capture images every minutes on my raspberry pi. I think something is not quite right as it has been taking pictures but not saves them. I wonder if someone could just ...
1
vote
3answers
49 views

Get directory name from file name

I want to make a directory name by extracting parts of a file name. Here are some examples: server.log.2016-03-20-14 → 20160320 server-2016-03-17-13-16-Restart.log → 20160317 I'm using HP-UX.
3
votes
2answers
50 views

Create directory named from file modification time

I want to create directory name from a file's modification time. For example, if the file creation or modification time is 03/17/2016 18:00:00 then I want to create a directory named 1703206. I'm ...
1
vote
1answer
50 views

Needed shell script modification to show IP and host DD-WRT

I am running DD-WRT v.3.0 on my Linksys EA6500 router and I have the following script running in order to give me access to the WiFi MAC address that are currently connected to the router: echo ...
0
votes
0answers
48 views

Command not found, only when used in a script

I installed pup on my mac using homebrew. When I try this command in my terminal cat index.html | pup -p 'div[class="quote"] text{}' >> quotes.txt it works fine but when I use it in a ...
5
votes
4answers
322 views

Use case / practical example for Bash' builtin exec

Consider this from the documentation of Bash' builtin exec: exec replaces the shell without creating a new process Please provide a use case / practical example. I don’t understand how this ...
0
votes
2answers
75 views

Move log file which is older than 2 days

I want to move log files which are older than two days to a new directory by date, like below. Source: 1) /Test1/Server.log 2) /Test1/Server17032016.log Destination: ...
0
votes
1answer
38 views

Problem: Having file name contain Space and fetch the file [duplicate]

I am trying to get all file which is reside in one folder and file name have space like 1)File Test 050791.xml and i am fetching using below command export srcfileTimeCheck="$(find $dir -type f ...