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

learn more… | top users | synonyms (2)

1
vote
1answer
34 views

how to get or reflect the name of the bash function which is called? [duplicate]

i did not yet found a solution to this. Anyone a hint? i sometimes write bash functions in my shell scripts and i love to have my scripts being verbose, not just for debugging. so sometimes i would ...
-1
votes
2answers
30 views

Search and output string from a file to xml

Received timestamp=1459434658969: ABC: Field id=0 double 11.4 DEF: Field id=1 string >def< GHI: Field id=2 string >g_hi< I would like to read a file that contains input in the above ...
-2
votes
1answer
63 views

When a particular file arrives then execute a procedure using Shell Script [closed]

When a particular file for eg: "abc.csv" file arrives into a directory for eg: "mydir", I need to execute a procedure using shell script. "There was a procedure which will load data from csv to table ...
-1
votes
0answers
66 views

How to write a shell script (.sh file) in CentOS 6 to run commands in different tabs in the same terminal

My commads.sh file so far, #Start the first service cd /home/user/service1 java -jar service1.jar sleep 5 #Start the second service #I need this to start in another tab (if cannot another terminal) ...
0
votes
5answers
115 views

How do I display all the characters between two specific strings?

I want to display all the characters in a file between strings "xxx" and "yyy" (the quotes are not part of the delimiters). How can I do that ? For example, if i have input "Hello world xxx this is a ...
3
votes
2answers
46 views

Iterating over glob patterns, not the files in them

I would like to perform the same aggregation operations on each of several bunches of files where each bunch is matched by one glob pattern. What I would not like to do is pipe each file name into the ...
1
vote
2answers
48 views

How to sum the output of two commands and save it to a file?

I have two kfsql commands that get total count of users. I need these two command outputs to be added up and printed to a file.txt I tried: var1= getdatabase1 var2= getdatabase2 echo "$var1" echo ...
2
votes
3answers
91 views

How to sort files in Bash with ddmmyy timestamps in name

I have a series of files with names of the form "foo.date.bar" where "date" is a six digit field such as 310715. So for example foo.310715.bar foo.260815.bar foo.110815.bar foo.040815.bar I would ...
3
votes
2answers
45 views

detect if PDF file is made from images

I'm trying to pre-process a huge amount of PDF files, many of them not actually text but images in order to move them to a proper location to OCR processing. The problem is I've tried to detect if ...
0
votes
1answer
33 views

Shell script that outputs chmod command for all files

On my EC2 Linux server, I blindly ran chmod 777 at directory that it turns out I should not have. There are hundreds of files in there, and I'm not sure which ones need to go back to their original ...
0
votes
2answers
48 views

How to get absolute path of current shell in a sourced script? [duplicate]

Suppose one executes either . some_script or source some_script How can some_script determine the absolute path of the current shell (i.e. the one that is executing the . or source command)? ...
0
votes
2answers
22 views

Shell script - child - background process

I have the following situation : As root Script_A.sh is run on the server and sleeps until triggered. When triggered, it calls Script_B.sh, which loops on the server to determine which actions it ...
0
votes
4answers
198 views

Obtain script current directory (so that I can do include files without relative paths and run the script from everywhere)

I have the following problem, my shell script contain something like: mydir='' # config load source $mydir/config.sh .... execute various commands My script is placed in my user dir.. let's say ...
1
vote
3answers
42 views

Unable to source file

I have a scenario where a tomcat user-defined configuration is stored in a file called tomcat.env. In catalina.sh we are sourcing the values as below: . "$CATALINA_BASE/bin/setenv.sh" But as the ...
1
vote
2answers
69 views

rename multiple files in multiple directories using Bash scripting

I want to rename multiple files in multiple directories using Bash scripting. I have 772 such directories i.e from Nishi_001 to Nishi_772. Each directory has different number of files in it but in ...
0
votes
1answer
39 views

Why is this script not copying the files inside my source directory?

I am running a script with two arguments. myshell.sh source destination So I want to copy all the files (not including subdirectories) inside the source directory and copy them to the destination ...
0
votes
0answers
38 views

I have a command not found error in my shell script when I run the code

when I run the code below I get the error message "line 19: checkUser: command not found". I have tried using shellcheck but I still couldn't fix the issue with the code. #!/usr/bin/env bash ...
1
vote
1answer
43 views

bash scripting - wget or curl file with action based on the status 200 or not

I would like to write a script where I try to download a file with wget (or curl if is really not something that can be done with wget) and do 2 actions if the file exists and it's downloaded ...
2
votes
2answers
49 views

Updating shell functions and aliases through environment variables

Say we define the following shell function and alias in .zshenv: export VARIABLE_A='original' function my_function() { print $VARIABLE_A } export VARIABLE_B='original' alias my_alias="print ...
1
vote
1answer
29 views

curl load IPs from Text file

I have a list of IPs and want to run a specific curl command on each of them. The command is: curl --user test:test http://192.168.1.1/security/pkm.html | egrep '@company|config.pkm.password' ...
1
vote
1answer
22 views

cron job for pure-quotacheck with pure-pw list [closed]

I want to automate the process of quota checks for a pure-ftp server. I've read the docs, so I can do that with pure-quotacheck -d /path2/home -u user The simplest method that I could think of is to ...
0
votes
2answers
46 views

use of if else in linux to find whether the folder exists or not

I have the following bash script: if [ -d "/$home/DB_handouts"] then echo "Directory DB_handouts found" else mkdir /$home/DB_handouts chmod 777 /$home/DB_handouts fi Running the above code ...
0
votes
1answer
50 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
41 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
34 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
47 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
24 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
19 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
45 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
49 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
61 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
35 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
93 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
54 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
79 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
40 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
34 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 ...