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

learn more… | top users | synonyms (2)

-2
votes
3answers
60 views

How to Show your main “shell” that you use.? in UNIX

How to Show your main “shell” that you use.? in UNIX is this command right ps -p$$ or if there is a different way? thank you
1
vote
1answer
48 views

Indented here document causes a syntax error

I have the following code fragment in my shell script and have a bug that I can't seem to pin down a reason for despite some research. When I run the code as below the script exits with a message ...
3
votes
2answers
202 views

Nested 'awk' in a 'while' loop, parse two files line by line and compare column values

I need some help with a combination of awk & while loop. I have two simple files with columns (normal ones are very large), one representing simple intervals for an ID=10(of coding ...
0
votes
1answer
37 views

mkvmerge in a bash script does not execute

I have made a script which does mux a videofile, multiple audiofiles and multiple subtitles into one .mkv. the script tries to run: "/usr/bin/mkvmerge" -o "test.mkv" "--default-track" "0:yes" ...
-1
votes
3answers
56 views

Error in `for` loop in `if… else` conditions

Hi guys I am new in writing bash script. I have a task to do. I have a file in which node name and IP addresses are updated, I have to make each file of those nodes which are not in our required ...
2
votes
1answer
84 views

Avoid “Shared connection to <host> closed” messages

I'm managing a lot of drupal sites, and trying to automate some stuff using drush. Drush run locally calls drush on the remote host via ssh using options specified in the config for the site alias. ...
1
vote
3answers
59 views

How can I create a relative symlink given a relative path?

I would like to programmatically find the directory depth of a relative path. So for example the depth of test/dir/hello is 3 More specifically I would like the directory depth so that I can create a ...
4
votes
1answer
24 views

Shell script: filter list of .pdf files, to exclude those with a .tex source file

I have a linebreak-separated list of file paths, all to pdf files. I would like to filter out all those which have a corresponding *.tex file in the same directory (and so can be presumed ...
2
votes
5answers
83 views

How to create a script that can't be easily exited

How would I create a script that does not respond to Ctrl-C? This should also prevent any processes launched by the script from being killed (I'm trying to keep apt-get upgrade from being killed). (I ...
2
votes
1answer
41 views

Updating config files within the script that references them?

I have no problem adding config files to a given script, but automatically updating them is another matter. In this instance I'm providing a few variables to a script, and I'd like the script to be ...
2
votes
1answer
87 views

How to make svn save credentials when --non-interactive

I'm trying to get svn to save my https username+password to ~/.subversion from within an automated script. I can pass creds on the command-line but I do not want to be prompted about whether to save ...
1
vote
1answer
75 views

awk with variables in condition and in output redirection file

I would please like some help with this command because I didn't find anything in documentation that can cover everything I want. I have some variables that are global, so I would prefer to keep them ...
0
votes
1answer
45 views

introduce a c script in a bash file [closed]

My problem is to recover data keyed in text file in bash. I seek the command that can perform this task and I used sed, awk and even cut but I have not succeeded. One friend of mine suggested to ...
1
vote
1answer
21 views

Store delayed shell output to variable?

I have a script which stores output of a command inside a variable like this: my_var=$(command) However, some of the output is not being stored in the variable, I am assuming because it is ...
0
votes
0answers
86 views

Where is the log_daemon_msg?

So this is my little shscript (my_init_script.sh) located in /etc/init.d/ #!/bin/sh . /lib/lsb/init-functions NAME=my_script_for_auto_update PIDFILE=/var/run/$NAME.pid ...
2
votes
3answers
115 views

How to run multiple scripts in parallel

I have one bash script which calls the same perl scrips in a serial way. The bash script is used to collect the overall results, while the perl script collects the results of my simulations for the ...
1
vote
1answer
66 views

awk pattern with variable in a bash script

I have problem with command awk in bash I want to find pattern with variable, but it doesn't work. Can you tell me what's wrong with this line? awk -F" " "/$PWD/ {print $1,$3}" file.txt
1
vote
1answer
68 views

How to get the http dump of a website and the header both from a single curl command?

I have to fetch a website (multiple redirections possible using -L) and save the html content in a file named as [HTTP_Status_code]_[Website_name].html Currently I am using two curl calls one for the ...
0
votes
1answer
52 views

Compare text files with grep

Lets say I have two files, I want to find goodbye which I can do with grep but what i'm struggling with is once I find goodbye matching the next line with the first column of file 1. File1 sss aa ...
1
vote
3answers
33 views

read -e in a sub script

Let's imagine that I have script1.sh and script2.sh with the following sources: Script 1: #!/bin/bash # script 1 echo "Doing some stuff..." bash script2.sh echo "Done" And Script 2: #!/bin/bash # ...
4
votes
5answers
281 views

sudo in non-interactive script

I have a script that executes three functions: A && B && C. Function B needs to be run as a super-user, while A and C doesn't. I have several solutions but neither of these is ...
0
votes
1answer
45 views

Command for setting DocumentRoot for apache on Debian?

So I am developing a simple installation script for a Raspberry based app. It installs the LAMP install, grants some permissions among other things. And part of the process is to change the apache ...
2
votes
4answers
151 views

Shell Scripting: Proper way to check for internet connectivity?

I found scripts that say they check for internet connectivity. Some check the ip address if the interface is connected BUT it does not check for internet connectivity. I found some that uses ping like ...
1
vote
3answers
65 views

Shell Scripting: Comparing something to nothing?

I have this script to check for internet connectivity. I use ping for it. Whenever I use ping google.com -c 4 | grep time it produces a non-empty response. Something like 64 bytes from ...
1
vote
2answers
23 views

Substituting file extensions on a variable

I'd like to do the following : create a .tex and directly show it after compilation with evince, ideally it would be like this: showpdf file.tex so I wrote #!/bin/sh pdflatex $1 && ...
0
votes
1answer
30 views

? appended to filename while copying from a ssh

I am using the command cp error.log error$HOSTNAME.log the command works properly while running it separately in a server, but if it is run as script which uses ssh I am getting a ? appended to the ...
3
votes
2answers
86 views

save the number of files only in a specific folder

I'm using this script to save the number of files in a main folder, but it also counts the subfolders inside that main folder. nfiles=$(ls -1 /home/userA/mainfolder | wc -l) Any advice how I can ...
1
vote
2answers
50 views

How to copy only files in a specified directory to another folder

I'm trying to copy only the files from one directory (not including folders or any files in its subfolders) to another location using cp /media/d/folder1/* /home/userA/folder2/. It is copying the ...
2
votes
2answers
62 views

Find out on which line in text file is matching word

Is there any way to find out on which line of the text document is some word which is matching pattern for example with grep or something. Thanks.
1
vote
3answers
114 views

GNU parted resizepart in script

I would like to used the yes command so that GNU parted does not wait for user input : root@195-xxx-xxx-xxx:/proc# parted /dev/sda unit B resizepart 2 1166016512B Warning: Shrinking a partition can ...
0
votes
1answer
81 views

Adding commands in a shell script to add a python module path

I want to modify a linux shell script used to install a python module (setup.sh) to add the folder the an environment variable. This is needed so I can run the python module from a terminal. e.g. ...
3
votes
3answers
546 views

Switch user in a shell script without entering the password

I'm running a shell script using terminal from userA. In the middle of this shell script, I switch to userB user using su, but this asks me for the password of userB and I have to manually enter the ...
5
votes
1answer
399 views

Shell command/script to see if a host is alive?

I'm trying to figure out more ways to see if a given host is up, solely using shell commands (primarily bash). Ideally, it would be able to work with both hostnames and IP addresses. Right now the ...
1
vote
2answers
44 views

Need special validation for shell script

I want to create a bash script which will have lot of options while executing. # script.sh --dry-run --user <parameter1> --pass <parameter2> I heard about getopt option but looks like ...
1
vote
1answer
42 views

Why do my run level directories contain only start scripts and no single kill script?

I learned here that for each runlevel exist a directory with start and kill scripts. The start scripts are activated on entering , the kill scripts on leaving the runlevel. Start scripts and kill ...
0
votes
2answers
105 views

Uses of hash in shell scripting [closed]

What are the uses of the hash character in shell scripting beyond using them in comments or as $#; what are other uses? I want to be able to grep the content on each line before hash since there are ...
2
votes
0answers
31 views

How to sort files by their dates into timestamped folders? [duplicate]

I want to sort about 2500 images every day into folders with a timestamp. So far I have this script but it's not working.... for x in *.jpg; do d=$(date -r "$x" +%Y-%m-%d) mkdir -p "$d" mv -- "$x" ...
0
votes
1answer
93 views

Translate Windows batch script into a bash script for Linux

I'm new to Linux and am trying to find the equivalent of this from Windows @echo off if ".%1" == "." goto TellSyntax set ...
1
vote
3answers
86 views

Simple install script says it is unable to locate package

This install script is giving me the error Unable to locate package for most of the programs. #! /bin/bash apps=( 'python-dev', 'python-pip', 'python-numpy', 'python-scipy', 'python-matplotlib', ...
1
vote
1answer
102 views

Bash: Looping through a string

I have a variable Vmac that stores values of multiple MAC addresses, collected from wmic call as follows: Vmac=`wmic --delimiter="," --authentication-file=/path/to/file //IP-ADDR "Select ...
1
vote
2answers
43 views

Some characters disappear after processing a text file

I've a file named addresses.txt : address1@domain.com address2@domain.com address3@domain.com I'd like to echo "address1@domain.com.html" using for loop. Here's what I did : cat addresses.txt | ...
1
vote
4answers
68 views

Delete all files in a directory

I have a directory which includes some files and some folders containing other files. I'm trying to remove these files in the main directory without touching the folders or their contents. I'm using ...
2
votes
1answer
35 views

Copy files that partially matches another files in another location

I have a list of jpeg files in a directory like this (below is just a sample, like the structure is the same but this there are many fo0# sub-folders, not only fo01 and fo01, where each of these ...
2
votes
4answers
183 views

Creating directories in a loop and moving files to those directories

Consider a directory with N files. I can list the files alphabetically sorted and store the list by ls > list Then I want to create n sub-directories in same directory, which can be done by ...
-2
votes
1answer
81 views

How to parse json output through shell / Python [closed]

I am running a curl command which gives me json response. Now I want to parse the response output to get the keys and corresponding values from the output or getting value for a particular key. I ...
1
vote
1answer
289 views

How to launch shell script with double click in CentOS 7

I need to be able to execute an executable shell script (sh) with a double click. I set the executable flag on the permissions for the file, and yet when I double click on it, it opens in a text ...
1
vote
2answers
68 views

Rename files depending on their parent directory

I have a main directory, let's say main. This main directory has some folders, among which are three folders named ccc ddd and lll, which are the only folders I want to target and work on. Each of ...
1
vote
1answer
36 views

Not getting the desired output for echo command [duplicate]

Below is my script. #!/bin/bash SERVERS="sl20rht00-t" #SERVERS="shcbrht01-t" USR="adm-dt-c" for host in $SERVERS do ssh -tt $USR@$host 'sudo cp /etc/sudoers /Backups/sudoers_11thmarch2015; sudo cp ...
0
votes
1answer
81 views

Detecting if ssh login fails

I have this line to run in a script, the issue is that I have to run the script over several hosts ( and it includes windows servers) and I don't know how to catch the error if the ssh receives ...
4
votes
2answers
121 views

Replace string in a file with another where both are saved in variables

I want to replace a string found in a file with another string, but both have a special character (in this example it is a . char) e.g 1.0 and 2.0. So this is the command currently used: sed -i ...