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

learn more… | top users | synonyms (2)

1
vote
3answers
109 views

Confused on user and su in linux

How could I run a script as a specific user (non-root)? As this? sudo su - john /usr/share/script.pl for user john?
0
votes
1answer
2k views

if condition, loop in grep [closed]

Could someone please provide help for me. I tried to start writing a shell script but am getting hung up with this issue. I need to grep commands "adb shell ps" and find in it 3 processes with names: ...
3
votes
1answer
350 views

A robust way to execute a command/run a script at login?

I have two commands that change keyboard behaviour: xset r rate 120 66 /usr/bin/setxkbmap -option "ctrl:nocaps" When I open a terminal and execute them, they change auto-repeat settings and remap ...
3
votes
4answers
429 views

Show video files with its size

I need all the .mp4 files' dimensions to be printed with the file name. For example: 1_VIDEO.mp4 1204x680
1
vote
1answer
443 views

What is the pipe character “x|y)” in the case statement?

In a script /etc/network/if-up.d/avahi-autoipd in my system, I find statements like this: case "$ADDRFAM" in inet|NetworkManager) ;; *) exit 0 esac case "$METHOD" in static|dhcp|NetworkManager) ...
1
vote
2answers
552 views

Grep a string from file

I have 5 filenames created inside a folder for one operation.The filenames are in the following format. ES_currentdate_currenttime_processid_uniqueid.log I want to read the status from the latest ...
-1
votes
1answer
2k views

Invoking shell script with -option and parameters

I need to invoke a shell script test.sh in the following manner: ./test.sh -run/-rerun username password How to check if they have passed -run or -rerun option inside my shell script?
1
vote
1answer
170 views

Script to restart the application

I need to write a script for the below scenario in Linux: Run a cron every 5 minutes. grep the application log file to see if we can see the pattern "ORA-". If we see this pattern: stop the ...
1
vote
2answers
4k views

Write a script to create users with pre-defined passwords

I need a simple script. One file named userID consists of 10 unixID and another file with name passwd consists of 10 password for those 10 unixID in file userID. The first word of each file ...
2
votes
2answers
13k views

Checking and changing file permission with script

I'm new to bash and I can't get a script working. This is the code that I have: #!/bin/bash file=~/scripts/text.txt if [ -e $file ] then echo "The file exists" elif [ ! -e $file ] then echo "The ...
2
votes
1answer
362 views

how to replace IP address on remote host using expect

I wrote the following expect script in order to replace the IP address on remote Linux machine I use a perl one-liner for this task I get errors about can't read "HOME": no such variable , Please ...
6
votes
3answers
6k views

How to remove lines included in one file from another file in bash?

I have two lists, a complete list and a partial list. I want a bash script that will search the complete list for any lines that are in the partial, if there are, they will be removed from the ...
2
votes
4answers
2k views

Bash source — select the right function when two sourced files have the same function name?

My bash script sources a script file (call it file2.sh) according to an argument. (It is either sourced or not.) The script file2.sh contains a function "foo" (call it a modified or improved version ...
2
votes
1answer
433 views

Is it possible to have comments in multiline commands in fish?

In bash it's possible to do my_function() { echo "hello" | #remove 'l' tr -d 'l' } but in fish ( http://fishshell.com ) I wasn't able to do the same: function my_function echo "hello" | ...
4
votes
2answers
28k views

Assigning the output of a SQL query to variable

I am connecting to oracle database and firing a query and assigning the output to variable But when I echo the value of the variable it doesn't get printed correctly. count=`sqlplus -s ...
0
votes
2answers
7k views

Extract a sub-string out of a variable's value

I have a string in the form of segment_78787 which is stored in a variable called $ID in my shell script. I need to get the second part "78787" and assign it to another variable. I tried like ...
2
votes
2answers
106 views

How can I execute a shell script that exists in a longish path with a single command without first cd'ing to the directory?

In Linux I always cd to a longish path and then run the script: cd /scratch/someDir/someOthernestedDir/ ./shellscriptName.sh How can I avoid achieve typing this longish path and then executing ...
0
votes
0answers
504 views

Error sending message, child exited 71 (Operating system error)

I'm trying to send mail through mutt command. I got the error message Error sending message, child exited 71 (Operating system error.). I was able to send email through this command earlier, but ...
2
votes
1answer
2k views

Environment variable for ip address

I see somewhere people use: IF_ADDRESS="$(echo "$IP4_ADDRESS_0" | cut -d'/' -f1)" to get the IP address in a network configuration script. In my system, I create a script under the directory ...
5
votes
4answers
808 views

Shell, Concatenating 2 strings to reference a 3rd variable

I am trying to do the following in my script: #/bin/bash -x var1=www var2=www2 var3=www3 var4=www4 for i in 1 2 3 4; do echo \$var$i done Obviously, this doesn't work as expected and results in ...
2
votes
2answers
1k views

how to add line in a /etc/sudoers file with the help of shell script (50servers)?

Anyone can help me with shell script, I want to know script which can edit /etc/sudoers file and let me add {{{{{userid ALL=(root) ALL}}}} to 50 server I have on same network?
2
votes
3answers
482 views

Exception handling when using tail -f to monitor a log

I have a main script calling the script to do the monitoring. I am trying to catch the exception that the log is missing or not accessible anymore. tail -f is used instead of -F since the logs are ...
1
vote
1answer
2k views

scp stuck when trying to copy files from Linux to windows

I use the following scp syntax in order to transfer a lot of files from Linux red-hat 5 to windows machine (under Temp directory). SSH server is already installed on windows machine. I use this line ...
3
votes
7answers
4k views

Problem in splitting a string using awk or cut command

I have a properties file which has a password field (key value pair) PASSWORD=NDhhHcsOBofXUdUzGw5B0Q== I am trying to get the value in my shell script using the awk command password=`awk -F "=" ...
5
votes
2answers
563 views

Prevent a file from being deleted even after rm -f

I usually stay on StackOverflow but I think on this topic you guys are much more experts here. So today's exercise is weird, I have to write a script.sh and in it do whatever I can to prevent ...
1
vote
2answers
932 views

/dev/null-like automatic trash directory for file moves?

I can (redirect) textual output to /dev/null in order to get rid of it. This is quite handy because this way I can easily enable/disable it in my bash code. Now I have a script that processes files, ...
15
votes
9answers
47k views

How to compare two dates in a shell

How to compare two dates in a shell script? For example something like todate=2013-07-18 cond=2013-07-15 if [ $todate -ge $cond ]; then break fi It doesn't work. ...
3
votes
3answers
2k views

How to delete files only, but keep the directory structure?

I would like to delete every file, but keep the folder structure. Is there a way? NOTE: (I'm using GNU bash 4.1.5).
6
votes
4answers
20k views

Shell script to send an alert mail if disk usage exceeds 90%

I am new to shell scripting and want to implement a script on my server which will automatically send email alerts if the disk usage goes over 90% and second email alert when it goes over 95%. My ...
1
vote
0answers
42 views

FuncName(){} vs function FuncName() {} [duplicate]

There is two ways to define function in bash script. 1. function FuncName() { echo "$FUNCNAME" } 2. FuncName() { echo "$FUNCNAME" } So my questions is what's the different between in ...
0
votes
1answer
388 views

Processing multiple mails in a Postfix mailbox by making cronjob run per second-is that considered good practice?

I need to process at least three thousand incoming emails an hour that are received in a postfix mailbox. Processing involves extracting email attachments and sending the content of an email ...
2
votes
4answers
2k views

Setting a variable whose value depends on another variable

i have a text file variables.txt where i store my variables host=/srv/www/vhosts/hosting index=$host/index.php as you see the second variables depends on the first one. i also have a ...
3
votes
2answers
11k views

Passing a variable to sed

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt ...
1
vote
3answers
452 views

Couting all characters by BASH character class

I need to efficiently count every character of an arbitrary file by its character CLASS (as defined by the BASH man page); i.e. [[:alnum:]], [[:alpha:]], [[:ascii:]], [[:blank:]], [[:cntrl:]], ...
2
votes
1answer
273 views

Passing values to a parameter in script

Following is the script to copy all libraries of a certain command to make my chroot environment. For example: ./cplb.sh /bin/ls will copy all the libraries of ls command (i.e., the files listed by ...
1
vote
0answers
27 views

Script executed from cron doesn't display GUI notifications [duplicate]

The script below has the name notifyrssh.sh. 1: File=/home/vaios/Desktop/tempcron/liveusers.txt //OK 2: cd /home/vaios/Desktop/tempcron 3: ps -aux | grep sshd > ...
0
votes
1answer
95 views

How do I change working directories with KDialog?

Use-case: I am working in the terminal in /path/with/a/very/long/name and I want to change to some other directory that is deeply nested. But I don't know the path by memory. So I want to browse via a ...
3
votes
3answers
753 views

Determine the last 7 days backup size

Consider I have a folder /home/abdul/backup which contains .gz file for the past 1 year...My requirement is to get the size of last 7 days...
1
vote
3answers
155 views

grep for strings that were found in a previous statement

I'm trying to find out if an address definition is used inside of fortigate configuration file. I extracted the section out of the configuration file, that contains the addresses. In that section the ...
0
votes
1answer
8k views

Formating Mail Body data into html table format

I have a hive query result in tab separated format. I am storing it into a file like query="select Name, age from table;" echo $query | hive > test.csv Now I want to send it in mail using mutt ...
7
votes
3answers
2k views

Optimizing a `while` loop

I have created a mini script to reboot my Raspberry Pi upon the push of a button. The script simply uses wiringPi (gpio command) to set pin 0 (pin 17 in Raspberry Pi standard numbering order) to ...
2
votes
1answer
762 views

Bash nested command substitution not working

Hi I have a bash script that intend to run via watch ./script.sh It's to debug a cooling problem with my laptop, however the script I wrote isn't working as intended. I'm quite new to bash scripting ...
0
votes
1answer
455 views

Pseudo-terminal message in script

This is my script #!/bin/bash exec < filelist.txt while read updatedfile oldfile; do # echo updatedfile = "$updatedfile" #use for troubleshooting # echo oldfile = "$oldfile" #use ...
1
vote
1answer
792 views

How to use kdialog progressbar from a Bash script when the bar was initialized in another script?

Here is an example of how to use the kdialog progressbar. It works. dbusRef=`kdialog --progressbar "Press Cancel at Any time" 10` qdbus $dbusRef showCancelButton true until test "true" = `qdbus ...
5
votes
2answers
9k views

Proper way to add a user account via bash script

I cross posted this question to AskUbuntu because my problem seems most acute on Debian/Ubuntu, but it was suggested that I ask here. Whatever method is suggested for solving this problem should work ...
1
vote
1answer
431 views

Bash script to hide/show files

I prepared a little bash script to toggle the visibility of my hidden OS X files. if (defaults write com.apple.finder AppleShowAllFiles FALSE); then defaults write com.apple.finder ...
1
vote
3answers
5k views

How to execute more than one command in a newly opened terminal?

I have a script that I want to use to open new terminals and type commands in them. A command like gnome-terminal opens a new terminal. Also, if I do gnome-terminal -e myprogram1 it will ...
4
votes
1answer
370 views

How Can I Automate the Change between a Python Script and a Nohup Python Script?

I have a Raspberry Pi connected to a digital temperature probe, which measures my fermenting beer. A python script reads the temperature every second and prints it to the console, and stores it in a ...
2
votes
2answers
61 views

How to paste same information into 2 different files?

I'd like to create two files in /etc/skel using a script which does many other things in addition to the creation of the files in /etc/skel. The part from script regarding /etc/skel looks like this: ...
5
votes
3answers
13k views

bash script error stty: standard input: Inappropriate ioctl for device

I'm using here-documents in a bash script to automate installation and setup where a password is required many times. I enter the password once and the script passes it to the various commands. In ...