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

learn more… | top users | synonyms (2)

0
votes
2answers
26 views

Is there a way for shell script to know which program has executed it?

In *nix world, is there a way for shell script to have information about which program has executed it? Example: /path/to/script1 /path/to/script_xyz in this imaginary scenario, script_xyz would ...
0
votes
3answers
48 views

How can I delete a line from a file when the line contains a specific string?

I have a file which is comma separated. I have to find specific text and then delete complete line. e.g. 123,aaa,bbb,888,8881 124,bbb,ccc,999,8881 125,ccc,ddd,888,8883 I have to delete the line ...
0
votes
2answers
21 views

Preform operation in bash only if a variable is less than a second variable

I am building an OS for a virtual machine I made, and while progress has been coming along swimmingly, I have been stuck for a good several hours on what should be a very simple issue: I am designing ...
-2
votes
1answer
75 views

quick and easy way to comment out multi lined print statements

Is there a quick and easy way to comment out multi lined print statements? something like this? printf("3387 strings_line_tokens[lower_bound_of_big_boy_counter] %s \n", ...
0
votes
1answer
48 views

How to actively grep log for the last 15 seconds for a phrase?

I have this bash script and inside the script, I am trying to grep a log for the words "status change" and then after I find the most recent line that contains the words "status change" (aka the most ...
0
votes
1answer
38 views

add multiple users to multiple servers

I have a quick bash scripting question. I'm trying to add multiple new user accounts to multiple RedHat servers in my environment. This the script I've come up with so far, but it's not quite ...
-2
votes
0answers
27 views

Script (shell or python) to update a web page every 5 minutes [on hold]

I'm trying to write a script (shell or python) to update a web page every 5 minutes. I tried this: import time from selenium import webdriver driver = webdriver.Firefox() driver.get('https://www....
1
vote
2answers
37 views

Condition Inside String in Bashscript

I want to print exit code of previous command in shell if it failed. So I changed PS1 variable in /etc/bash.bashrc like this: PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w [$?] \$ ' #...
1
vote
1answer
96 views

tail file from remote server and nslookup on local

I need a script for resolve hosts. For now I run this script on local machine for i in `tail -F access.log | awk '{print $8}' | awk '{gsub("http://|/.*","")}2' | awk '{gsub("http://|:.*","")}1' | ...
0
votes
2answers
37 views

if last 4 file size of a directory are same with each other then exit otheriwse continue [on hold]

Please give me any shell bash script that will help me doing following task: if last added 4 file size of a directory are same with each other then exit other wise continue Example : ls -l $...
1
vote
2answers
134 views

#!/bin/bash exponent

I'm having trouble running exponent operator in a shell script #!/bin/bash clear number1=8 number2=2 sum1=$(( number1 ** number2 )) echo "8 ^ 2 =" $sum1 it returns expecting primary: " number1 *...
2
votes
1answer
371 views

Error “dircolors: no SHELL environment variable, and no shell type option given”

Running Linux Mint 17.3 Cinnamon A while ago a created a script that changed the colors in the Terminal (to match a tutorial I was following) However if I open the terminal on another account, I get ...
0
votes
0answers
20 views

taking the input from one file and related info from another copy it to new file

I have a inputfile contains phone numbers like 7463213456 8725678845 In another file I have info for every file like 7463213456;553256324;HIW456DFC;base_rsa;VSHD*CFGH...................... ...
2
votes
1answer
45 views

Cut string from command output

I would like to cut 150.8 from this string temp1: +150.8°F (crit = +197.6°F). Here is my script for logging temperatures with the command sensors: #!/bin/bash now=$(date +"%m_%d_%Y") # ...
3
votes
1answer
36 views

“) Syntax error Invalid arithmetic operator (error token is ”

I have commands in a bash script getting data from a source text file and then adding the value of a variable to it and using it in an if/else condition. Source data file (db_count.ini) (Note: ...
0
votes
2answers
23 views

Removing space at the beginning of the variable data

I would like to ask if how can I remove the space in the beginning of the stored data of the variable. I had an auto-generated script that will get MySQL COUNT from the DB. MYSQL COUNT SCRIPT-> .ini ...
0
votes
1answer
9 views

Multilevel Menu-Submenu-Option bashscript ( If-Else vs Switch-Case ) [on hold]

I'm asking for suggestion which one is better for Menu-Option especially for the process after you choose option it will have a option back to the menu. Please see below [Menu] 1 - Option 1 2 - ...
6
votes
7answers
343 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 ...
-1
votes
0answers
19 views

Monitor Script for a specific oracle process which pegs my CPU to 100 % [on hold]

I need a shell script on AIX which can monitor a specific oracle process "ora_e00", this process is often pegging my CPU 100%, so I need to be notified by mail before killing it.
0
votes
2answers
51 views

How to execute a shell script from anywhere on my server?

So basically I have a JS app that is inside a directory in /var/lib/app/. To start this node app I execute a start script startapp.sh from inside the directory. Now I need it to start at boot time, ...
1
vote
0answers
32 views

mutt doesn't run as a cron job wrapped in a bash script

mutt runs correctly like this: $ cat /home/user/test this is a test $ mutt -s "test" to@destination.org </home/user/test If I put this inside a bash script (stored in tmp1): #!/bin/bash /usr/...
7
votes
3answers
662 views

How can I safely ensure a variable contains only a valid filename?

Given the script below, how can I ensure that the argument only contains a valid filename within /home/charlesingalls/ and not a path (../home/carolineingalls/) or wildcard, etc? I only want the ...
1
vote
2answers
977 views

Find last line of a file for matching string?

I want a loop that runs infinitely over a file but always checks the last line to see if it contains the matching string if it does then echo that line and keep the loop running. What I have right now ...
5
votes
2answers
385 views

Shell script: if multiple conditions

I want to create a shell script that echos something if 3 directories don't exist. Here is the code I wrote: test.sh: if [ ! -d "/home/unix/POSTagger2" ] || [! -d "/home/unix/POSTagger2/stanford-...
0
votes
0answers
18 views

Input Return Key In A Sql script

I have a sql script which when run prompts me to input a value, if i don't input any value and press the enter/return key it will select the default value and will pull all the records. I am trying to ...
-2
votes
2answers
43 views

Find ONLY the difference (extra) between two files in unix

I have 2 files. names1.txt and names2.txt. I need to know that which names are present in names1.txt but are missing in names2.txt. Then I need to store them in another file missing_names.txt. Diff ...
24
votes
6answers
2k views

How can I propagate my SSH pub key to a list of servers without having to type my password in over and over?

I was recently given username/password access to a list of servers and want to propagate my SSH public key to these servers, so that I can login more easily. So that it's clear: There is not any ...
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 ...
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
26 views

Get Timestamp 00:00:00 Yesterday in bash shell

I have a script want to get timestamp in begin yesterday (00:00:00 GMT+0) but cannot excute this script dateto=$(date --date="1 days ago" +"%Y-%m-%d") datetoj=$(date +%s --date "$dateto 07:00:00") &...
0
votes
2answers
40 views

Define a set of values for a variable in shell script

I want to define a set of values for a single variable. E.g. singleDigit={0,1,2,3,4,5,6,7,8,9} If the user gives 10 it should exit with an error. How can this be achieved without using a loop, but ...
-3
votes
2answers
167 views

Find the number of files with sizes

Find the number of files with sizes > 100KB in /, /bin, /usr, /usr/bin and /usr/sbin directories and output them in a two column format with the name of the directory and the number of files.
-10
votes
2answers
221 views

replace the the first line of all .sh files in a folder

Create list of all .sh files in current folder. Check first line of each file in this list and if file starts with #!/bin/sh then replace that with #!/bin/bash. Only modify files that have #!/bin/sh, ...
1
vote
1answer
32 views

Rename multiple directories at once

I have a project with many directories named proj $ find . -iname proj ./include/proj ./src/proj ./lib/proj ./share/proj ./doc/proj I want to rename all these directories to test with -exec mv. I ...
2
votes
2answers
52 views

How to assign value to input variable in shell

I am asking user for input and taking input in the variables such as $1, $2 etc. I am checking the variable for null value and wants to replace the value if null. if [ "$2" == "" ]; then 2=value fi ...
0
votes
4answers
45 views

read phone numbers from file and store them in other file uniquely

I have input text file e.g myfile.txt which is contains data like WO_ID ------------------------------------------------------------------------ moveover_virus_8493020020_virus.final ...
29
votes
4answers
25k views

What is the meaning of IFS=$'\n' in bash scripting?

At the beginning of a bash shell script is the following line: IFS=$'\n' What is the meaning behind this collection of symbols?
-3
votes
0answers
31 views

How to find sum of 2 columns in multiple line records file

I have file that looks like: .Employee name:ABCD department:1 salary:1200 bonus:120 - .Employee name:Aaa department:2 salary:1800 bonus:200 I want to create csv file called Employee with records ...
0
votes
1answer
37 views

How to use a for loop inside an echo statement which is used to print statements into another script in UNIX

My shell script contains a function which is used to print statements to another shell script function print() { echo " insert() #insert function for i in $InsertFile1 ...
0
votes
1answer
162 views

Sudo Apache, with command line ? (not visudo)

I have visudo-edited /etc/sudoers this way: User_Alias APACHE = www-data Cmnd_Alias FIREWALL = /sbin/iptables, /sbin/ifconfig, /sbin/route APACHE ALL = (ALL) NOPASSWD: FIREWALL (To allow php ...
0
votes
1answer
25 views

cannot open file as first argument [duplicate]

I am trying to run a script like : ./script.sh file but I am receiving ( if I use a txt file ): =: cannot open `=' (No such file or directory) test.txt: ASCII text Second If I use a gz ...
3
votes
3answers
109 views

How to read a properties file into an associative array?

I'd like to read the properties in a properties file into an associative array. How can I do it? Specifics on what to parse: hash and equal signs. Everything else is a bonus. Properties file content ...
0
votes
1answer
56 views

Read Input From Command Line

Trying to use the "read command" to accept user input from the command prompt itself but my script doesnt seem to be moving forward echo "Do you want to continue?(yes/no)" read -p $1 if [ "$1" == "...
-1
votes
4answers
40 views

Extract files from a directory and save the files' names and sizes in KB in a CSV file

I want to retrieve all the .log files from the directory /var/log, store the results in a csv file along with each log file's respective file size in kB. I started by getting the files using find: ...
0
votes
1answer
27 views

Automate commandline application for another user

i have a problem with the following command. I want to write a script that sets the vncpasswd for another user. If I run the following command it will only work for the current user. #< echo "...
1
vote
2answers
42 views

Quoting the output of a backtick command [duplicate]

I'm trying to run an expect script that runs a telnet session to automate the sending of an email, I'm trying to pass the contents of a file as a single argument to my script but when the backticks ...
0
votes
1answer
60 views

mv not working in script, but works fine on the commandline

I am trying to put together a simple script that renames a few files and directories. If I type the entries directly on the commandline they work fine. But as soon as I put them in a script it doesnt ...
21
votes
3answers
37k views

Variable as command; eval vs bash -c

I was reading a bash script someone made and I noticed that the author doesn't use eval to evaluate a variable as a command The author used bash -c "$1" instead of eval "$1" I assume using eval ...
0
votes
1answer
44 views

sed works on commandline but not in script [on hold]

Why does this work when I type it direct on the commandline: oldversion=12345 newversion=67890 sed -i "s/${oldversion}/${newversion}/g" "/home/user/MyDir_${newversion}/MyDir_${newversion}.reg" But ...