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

learn more… | top users | synonyms (2)

0
votes
0answers
27 views

executing shell script from launcher, slow to end/complete the script

I am using a bash script to rotate my screen via xrandr. To make it easier to use I added the script to the unity launcher. The problem I have encountered with this is that the script seems to ...
2
votes
2answers
87 views

Rename multiple files via shell script

I want to rename the following files 0 , 0.001 ,0.002 , 0.003 ... , 0.035 into 0 , 1 , 2 , 3 ... , 35 How can I do it?
2
votes
1answer
65 views

Shell: mutual piping of STDIN/STDOUT of two commands [duplicate]

When we run this with a POSIX shell, $ cmd0 | cmd1 STDOUT of cmd0 is piped to STDIN of cmd1. Q: On top of this, how can I also pipe STDOUT of cmd1 to STDIN of cmd0? Is it mandatory to use ...
3
votes
3answers
150 views

Could not execute a Bash Script if / while

I would like if someone points out mistakes in my script. The source where I'm learning from is so buggy that's why it's confusing me. PURPOSE OF THIS SCRIPT: It will count the numbers from ...
4
votes
3answers
188 views

Shell script: “if file is not being used” condition

I'm trying to compress a virtual machine image file through a script, but I want to be sure the file isn't being accessed. I could check if virt-manager is running, since it should be the only program ...
-1
votes
1answer
51 views

How to combine two files by shifting the value of the row file to its corresponding value in the column file?

I have a two files, the first has one row while the second with one column I would like to combine the two files by shifting each value in the row file to the same value in the column file, then ...
-3
votes
0answers
35 views

Outer loop stops without reading all lines of files when inside loop finishes in a nested while loop [closed]

I'm trying to use the below script to repeat actions to each line of the FILE. Inside the read while loop, I use another while loop to control the SYSTEM_COUNTER not to exceed MAX so that the system ...
2
votes
4answers
65 views

Redirect script stderr & stdout to a file, but keep stdout to tty as well?

In my script, I currently have: exec > >(tee -a /tmp/history.log) 2>&1 This writes both the stderr and stdout of all commands to both the log file and the tty. Unfortunately, this ...
0
votes
0answers
38 views

Mixing command substitution and extended globbing [closed]

The output below is admittedly artificial, but it illustrates the problem. To which paren is this error referring? syntax error near unexpected token `(' $ cat variables -a "a b c" -b "d e f" ...
0
votes
2answers
37 views

How to call script which is having menus, from another script

I have a script called operation.sh and while i am running the script, will be getting output like below and will wait for user input. 1. Start 2. Restart 3. Stop 4. Status Enter Option: Once ...
1
vote
1answer
37 views

Output in variable shouldn't be interpreted as command [duplicate]

So this question was asked some times already, but the answers didn't seem to work for me. So I have this simple script #!/bin/bash charon_id = $(pidof charon) kill -1 $charon_id And console says ...
6
votes
1answer
266 views

Check if variable equals open parenthesis

I'm currently trying to figure this out. if [ $CHAR == ( ] Obviously, this doesn't work. So how do I force it to do what I obviously intended? (For bonus points, how do I get the comparison to ...
1
vote
2answers
73 views

Timestamp not getting updated

I've written a piece of code but time stamp is not getting updated. It displays the time when the script runs and keep on displaying the same time even when loop is running and time is getting changed....
6
votes
1answer
88 views

How does sudo work (besides setuid)?

sudo is elevated to root upon launch because it's binary has a setuid enabled. But when I give /bin/login the exact privileges sudo has, and I try to run it from a user that isn't root, I get the ...
0
votes
1answer
40 views

Is there a function in shell script equivalent a var_dump(PHP)

I am beginner and I have a doubt in shell script. I'm doing some examples following this tutorials as: and I was curious to know if there is this kind of function in shell (var_dump PHP) because I ...
-3
votes
2answers
49 views

Bash scripting using #1 & #2 params but if files not found reverting to read from user [closed]

So if my user types in bash copy.sh copysource.txt copydest.txt - and the files are valid I want copysource to append to copydest and then show the file via cat -if the files names are NOT correct or ...
0
votes
1answer
24 views

Transferring a variable from one file to another

I have two files, config and template, and I want replace parts of the template with variables from config: config.txt contains: MYURL='www.google.com' template.txt contains: url = MYURL I used ...
1
vote
2answers
52 views

How to use exit status in crontab

I add the following script line to the red-hat crontab, script should run on Saturday in 5:00 in the morning. In order to run the script /var/scripts/PLW.pl every Saturday at 05:00 morning. I want to ...
1
vote
2answers
38 views

How to execute script located in the same directory as current script?

Why shell scripts are so hard to develop? In NodeJS I could simply do: require('./script') and it will always require script relative to current script. But if I try that in shell/bash: ./script....
1
vote
1answer
33 views

Assign continuous stream to variable and process the variable

I'm trying to make an analyzer for a custom log that I have. My log file has a duration timestamp (in ms) which I want to filter out from the others and send me the logs that take over a threshold ...
2
votes
2answers
256 views

How to count values that match a certain condition?

I have file with number of columns for example input file 12 15 27 5 6 48 19 16 25 17 23 37 etc I want to count all the numbers (X) in column 2 for example that fulfill the ...
2
votes
1answer
26 views

UDEV Rules Interfere

I am working on Raspian OS (Linux) for Raspberry Pi 3. I am trying to do a simple task say when I connect any USB to the port it should copy the data from a particular location to the USB and clear ...
0
votes
1answer
25 views

Execute script in new tab command line gnome-terminal

Hello i want to open a new terminal and execute a script immediately to it (to set a title in the new tab) and i cannot configure this. I try: gnome-terminal --tab-with-profile=$varname -x ./test.sh -...
1
vote
2answers
31 views

Install the content of a folder into another

I'm trying to write a Makefile to install the content of my folder into another on the system. I would like to keep the same directory structure, like this. localfolder ├── a └── b ├── c    ...
-1
votes
2answers
33 views

Privilegies of command inside shell script

I need to run simple script to check host status (ping), I have following script: #!/bin/bash echo "Host checker:" if [ "`ping -c 1 172.17.10.1`" ] then echo "HOST UP" else echo "HOST DOWN" fi ...
-2
votes
2answers
44 views

Insert a character at a specific location in ksh

My input is LOAD_DATE = 20072016 I want the output as LOAD_DATE = 20-07-2016 This is sample date. Date will come through LOG_DATE=echo ${LOG_FILE_NAME} |cut -d"." -f3 Sample dates "20072016,19072016,...
0
votes
0answers
16 views

Shell script output used as an sql script [duplicate]

Suppose I am using the following script #!/bin/bash PREFIX="A2B1 " TABLE="sqltablename" COLUMN="sqlcolumnname" if [[ ! -r "$1" ]]; then echo "unable to read file '$1'" exit 1 fi cut -d, -...
-4
votes
0answers
22 views

Taking the value of a particular column from each line and updating a table in a sql db

My csv file students.csv contains records in the following format : (student name , college ID , Roll no ) I have a table named "student" in my database having records in the same format .What I ...
1
vote
2answers
73 views

A script to take data from csv file and perform related operations in a database

I am new to the world of shell scripting and don't have much idea of shell scripting . My work requires me to write a script which takes phone numbers from a list of records stored in an CSV file . ...
-2
votes
1answer
27 views

add two numbers in bash script [closed]

Noob here. I was trying to add 2 numbers from command line and I can't figure out why I am getting the output as 0. #!/bin/bash args=("$@") if [ ${args[0]} -eq ${args[1]} ] then echo "The sum ...
0
votes
1answer
19 views

Running a series of scripts in MySQL

I have files named like: File1_01.sql File1_02.sql File2_01.sql File2_02.sql I need to run all the scripts for File1 first (but these can be done in parallel), then all the scripts for File2. What'...
1
vote
5answers
88 views

Killing a named process older than X minutes? (no killall -o)

Okay, first post! So I have this situation where I need to check for a process older than 5 minutes by a particular process name. The problem is that the system in question is a customized version of ...
0
votes
0answers
51 views

copying a file via a linux bash script: seemingly not working

Below is a simple script I have written to collect data contents of files from different directories named dyn1, dyn2, dyn3 ... dyn15. I will add more to the array list (other file names) but for now ...
6
votes
7answers
346 views

How to secure a sudo - powered script

Solution for executing root commands as unprivileged user - sudo 'ing script - easily opens possibility of security breach and unexpected behavior and results (this is also true for any other solution ...
0
votes
1answer
26 views

Move selected information form one TXT file to ANOTHER

I have two txt files: config.txt and template.txt template.txt has to take relevant information from config.txt Let's say config.txt contains: colour1: red colour2: blue And template.txt contains:...
0
votes
1answer
27 views

Linux redhat crontab + run script with arguments

I add the following line to the red-hat crontab in order to run the script /var/scripts/info_from_all_sites.bash every Friday at 00:00 night script should get as argument the file - /var/RT/names....
2
votes
2answers
29 views

finding a folder names based on list contained in .txt file

I have a .txt file containing 150 different ID number on each line like so: 12345 15876 19643 12586 Located in the same directory as the .txt file, I have 300 folders and I want to copy only the ...
2
votes
2answers
48 views

Bash function comments before or inside the function [closed]

Does the Bash language have a standard that dictates whether comments about the function should precede the function or be placed inside of it. I have seen scripts written both ways. # Comment ...
7
votes
7answers
344 views

grep the exact block of lines (content of file1) from file2

I have two files, file1 and file2. The sample content of file1 is: A B C D E F G H and the content of file2 is like: A B few other lines E F few more other lines A B C D E F G H few more other ...
3
votes
1answer
101 views

Handling whois connection refused message in shell script

blacklist_ips=' 5.56.148.140 94.73.159.66 69.134.15.72 107.150.42.226 195.159.233.44 89.19.7.58 ' for ipx in $blacklist_ips do country=`whois $ipx | grep -i country | tail ...
0
votes
1answer
33 views

Automatically put content in for read in bash

Hi I have a little bash script and before i used to type the content in a bit like answering a question, but what i would like to do is just run the bash script and instead of answering the question ...
2
votes
1answer
39 views

Search for files inside multiple subdirectories and zip directories [duplicate]

I need to extract more than 2k files from 1000 folders..the problem is, each folder has a zipped folder inside and inside this folder, there is another folder called "fileholder" which contains some ...
-1
votes
1answer
33 views

cancel script execution and continue [closed]

I have a script which runs another script. myscript.sh #!/bin/bash .... cd /folder/ sh run.sh sh another_script ... the procedure: So , I start running myscript.sh , the script runs it's ...
3
votes
0answers
114 views

How can I run 'ls' with options from a C program? [migrated]

I want to execute the command ls -a using execv() on a Linux machine as follows: char *const ptr={"/bin/sh","-c","ls","-a" ,NULL}; execv("/bin/sh",ptr); However, this command does not list hidden ...
14
votes
3answers
415 views

Replace environment variables in a file with their actual values?

Is there an easy way to substitute/evaluate environment variables in a file? Like let's say I have a file config.xml that contains: <property> <name>instanceId</name> <...
0
votes
0answers
47 views

Regular expression in expect command

I need to match a string and a newline with a regular expression or something like split when using the expect command on Linux. Here is the example of the command output: Notification value: 34 39 ...
1
vote
4answers
93 views

/bin/ls: Argument list too long

I am a biology person and running a program named autodock. I have some files from ZINC library in .mol2 format. As per requirement I need to split this files with the csplit command and I received ...
1
vote
2answers
59 views

chown doesn't work through script

I have a script: #! /bin/bash sudo chown -R $USER:$USER /opt/Folder The chown doesn't seem to execute. If I just write the above line from terminal ,it runs fine though! I have read this but ...
3
votes
1answer
40 views

Rename directories from “fname [mname] lname” to “lname, fname [mname]”

I have a bunch of directories with author's names as "first [mi] last" (middle initial/name could be multiples), and I'd like to change them to "last, first mi". So I'd like a way to parse the name ...
0
votes
2answers
66 views

im getting “syntax error near unexpected token” error in my shell script

when I run the particular command in a console it works fine but when I run using start script..it throws error. #!/bin/bash # chkconfig: 2345 20 80 # description: Description comes here.... # ...