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

learn more… | top users | synonyms (2)

0
votes
1answer
86 views

syntax error: invalid arithmetic operator (error token is “.c”)

I am trying to test if file "file1.c" is present in the current working directory, what am I doing wrong with my test command? I thought I understood this command, am I doing something wrong for the ...
-1
votes
3answers
60 views

Why am I getting an error “print_unicode: line 9: printf: missing unicode digit for \u Unicode 0187” with this script

I have written them following shell script to view what the Unicode characters look like on my terminal. #!/bin/bash X=0 while [ $X -lt 65536 ]; do HEX=`bc <<< "obase=16; $X"` ...
0
votes
0answers
37 views

Is there a BASH protection on remote copy of root files?

I am trying to use a script to bring back log to the admin. This script is send and load via mussh on the remote machine #!/bin/bash scp files.log user@user:~/ (I have also tried with sudo scp ... ...
-4
votes
2answers
53 views

syntax error near unexpected token 'else' and possible incorrect indentations help needed

I'm trying to write a shell script which creates a user then ask the user which group name the user wants to assign the user which they have just created to and at the end it needs to ask if the user ...
0
votes
2answers
26 views

BASH How to save the output of rm -vri to a var [duplicate]

How can I save the output of this command into a var and still remove the files? rm -vri files | wc -l
0
votes
1answer
22 views

Loop mount over an array (name has a space) [duplicate]

So I'm trying to write a small script that loops over an array list like so if [ $EUID != 0 ]; then sudo "$0" "$@" exit $? fi echo "Please enter repo password" stty -echo read PASSWORD stty ...
3
votes
2answers
51 views

Script doesn't wait for subprocesses from a loop

In a bash script I iterate through folders looking for some files, and if I find them I call a function with the directory that holds those files. See below pairedread $1 & pairedread $2 & ...
1
vote
2answers
53 views

Copy files from a directory if name present in a text file

#!/bin/bash while IFS='' read -r line || [[ -n "$line" ]]; do cd /home/Sud/Minimal\ Packages/All/ if [ -d $line ] then cp $line*.rpm /home/Sud/NewFolder/rpms/ else ...
-2
votes
2answers
62 views

How to copy one directory to a group of servers

I need to copy a directory to different servers, which are listed in a text file (hostfile). I haven't found any way to do something like this with scp scp -r --hostfile ~/directory ...
1
vote
6answers
36 views

Is there any way to find a process (or at least the existence of a process) by working directory?

I know that you can find the working directory of a process a few different ways, but is there any way to do the reverse? I have some server applications written in node that are unfortunately tricky ...
3
votes
4answers
132 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
37 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
44 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
60 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
43 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
46 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
26 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
55 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
35 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
29 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
37 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
126 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
46 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
141 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
38 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
47 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
39 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
45 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
53 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
48 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
41 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
65 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
57 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
36 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
79 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
32 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
69 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
79 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
140 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
105 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
33 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
55 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
31 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
28 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
52 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
96 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 ...