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

learn more… | top users | synonyms (2)

0
votes
2answers
30 views

Find the time of the file received in a particular directory

I have a directory called /home/mydir/test A file will be sent from some other team which lands in this directory. How to find what is the time the file came to this particular directory? ( I need ...
4
votes
1answer
189 views

Display cron job times in a human-friendly format

Is there a way to display or is there a tool that can parse a crontab expression and display it in a human-friendly way? 10 6 * * * sh /usr/local/crons/file_check.sh For example, for the above cron ...
0
votes
1answer
17 views

Adjust a script to get only certain rtvscand output report

I have the following working script: for i in `cat list` ; do ssh root@$i "uname -n ; cat /opt/Symantec/virusdefs/definfo.dat ; service rtvscand status ; echo ...
0
votes
1answer
22 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
2answers
18 views

link cut, find length and cut the new text with the first text's length

I'm stuck up with the below situation. there are two files - sample.war & sample1.48.war now, I've to cut only the first field of the first file. i.e., 'sample'. Next, I've to count the total ...
0
votes
3answers
35 views

Shell Script to change locale has no effect

I wrote a simple script to switch my locale. If I write each line in the console and execute it, it works without any problem or if I put it in .bashrc. However when I execute the script either with ...
8
votes
1answer
6k views

Trap, ERR, and echoing the error line

I'm trying to create some error reporting using a Trap to call a function on all errors: Trap "_func" ERR Is it possible to get what line the ERR signal was sent from? The shell is bash. If I do ...
1
vote
1answer
35 views

Pass list of directories (that contain whitespaces) to a command in a script

For example, I want to execute the following within a shell script: tar cvpzf /destination/backup.tgz /directory\ one /directory\ two I wish to assign the list of paths (with whitespaces in them) ...
0
votes
2answers
65 views

Why does this command not remove files as expected?

This command in my .sh script is supposed to look in /home/backup/VBtest for .sql.gz files and remove any older than 5 days: find /home/backup/VBtest/*.sql.gz -mtime +5 -exec rm {} \; But it ...
3
votes
2answers
7k views

Shell Script - syntax error near unexpected token `else'

With the following shell script, why I am getting errors syntax error near unexpected token `else' Shell Script echo "please enter username" read user_name echo "please enter password" read -s ...
1
vote
2answers
101 views

How to script with systemd-cgtop?

The manpage for systemd-cgtop says that if there is no attached tty it will do one iteration and then print it out, saying that this would be useful in scripts. However when I try to do this from a ...
0
votes
1answer
28 views

how to trigger sms from unix (shell script) [on hold]

How can I trigger an sms once a command is executed using shell script? for eg. cat file (one above command is executed (irrespective of the result), I should get an SMS
4
votes
1answer
660 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
6
votes
2answers
77 views

Notification Listener Behaving Strangely when Backgrounded

I've been struggling to get my IRC-Bouncer/Notification Script working. This is meant to be a script which will automatically login to a remote machine, attach to a screen session (or start one if ...
0
votes
1answer
20 views

Replace the first word of each line with its MD5

I have file with two space separated word in each line. I am looking for shell scrip in Unix to replace the first word of each row with its md5 hash representation. I have tried to adjust what is ...
1
vote
1answer
2k views

Deleting Non-empty Directory with smbclient

How can I remove a non-empty directory with smbclient? I have tried the following: 1) rm Result: NT_STATUS_NO_SUCH_FILE listing [dir_path] 2) recurse;rm Result: No Error but also nothing ...
0
votes
1answer
38 views

What means echo“{@@##}”?

We got a script that we need to understand, and at some point, we got this syntax: if [ "$PASS_CHAINE" = "TRUE" ] then echo "Launching DEGAGEMENT" | SLog cd $INTERFACE_D/bin_cm/deg ...
7
votes
3answers
6k views

Get path of current script when executed through a symlink

I have a utility consisting of a couple directories with some bash scripts and supporting files that will be deployed to several machines possibly in a different directory on each machine. The ...
-2
votes
1answer
22 views

copying a text from one file and pasting into other using shell script

I want to copy the number in a particular line from one text file and paste that number to other text file, how to do this using shell scripting. For example in file1 I have a line Total Time: ...
0
votes
1answer
42 views

Pushing to a Git repo from shell script

I'm trying to commit/push changes to a remote Git server with the below sample code: #!/bin/sh USER='username' REPO='/home/'${USER}'/Sites/git/bitbucket/kb' COMMIT_TIMESTAMP=`date +'%Y-%m-%d ...
0
votes
2answers
58 views

how to run multiple commands with awk via ssh?

I am having difficulty on the command below. Something is not right with the awk command. I tried putting backslash but still no good. Anyone can pin point where is my syntax gone wrong? for i in ...
1
vote
1answer
22 views

How to timeout and exit, if a sql query takes more than 10 minutes to get the results

I want to execute a select or update query. Sometimes the result is not fetched on time. As per requirement in different test conditions, I have to fail the tests if I dont get result in 5 minutes or ...
19
votes
8answers
5k views

How to efficiently generate large, uniformly distributed, random integers in bash?

I have been wondering what would be the best way to get good randomness in bash, i.e., what would be a procedure to get a random positive integer between MIN and MAX such that The range can be ...
1
vote
1answer
24 views

Detecting file size and do operation conditionally

In my main_dir, I have a lot of sub-folders say DFT1 to DFT150, and in each directory, there is a file named OSZICAR. However, some of this would have file size 0. So I would like to have a script, ...
1
vote
2answers
748 views

Command/scripts to check the Reverse DNS Lookup time

I am working on a project in which one master communicates with numbers of slaves. For that it has to make connection with hosts in network. But sometimes it hangs. I think that the reason behind is ...
0
votes
0answers
27 views

shell script in doing operation for 2 folder tree [duplicate]

I have a directory looks like: dhcp-18-189-47-44:CE-06-new-stuctures_backup wenxuanhuang$ ls DFT-00001 DFT-00004 DFT-00007 DFT-00010 DFT-00013 DFT-00016 DFT-00019 DFT-00022 DFT-00025 DFT-00028 ...
0
votes
1answer
26 views

extract subfolders outside and rename if necessary

I have a directory looks like: dhcp-18-189-47-44:CE-06-new-stuctures_backup wenxuanhuang$ ls DFT-00001 DFT-00004 DFT-00007 DFT-00010 DFT-00013 DFT-00016 DFT-00019 DFT-00022 DFT-00025 DFT-00028 ...
0
votes
2answers
56 views

sed in while read loop doesn't complete commands

I have a test file called testPage with the following text: || '''Title1''' || '''Title2''' || '''Title3''' || || Cell11 || Cell12 || Cell13 || || Cell21 || Cell22 || || Cell31 || Cell32 || || Cell41 ...
0
votes
1answer
58 views

How can I merge 3 commands and execute them

I'm try to run a script that figures out the paths based on the hostname: e.g. if hostname returns computer1 I would like to run path/to/Computer1.py (where path/to is a path that will always be the ...
0
votes
1answer
21 views

How to spawn new processes for new instances of the same shell script?

I'm trying to lock a file using the command lock. It's syntax is ./lock </path/to/file/name> I need to lock a bunch of files in a given directory and in order to achieve this I'm using two ...
11
votes
5answers
32k views

Add lines to the beginning and end of the huge file

I have the scenario where lines to be added on begining and end of the huge files. I have tried as shown below. for the first line: sed -i '1i\'"$FirstLine" $Filename for the last line: sed -i ...
1
vote
1answer
29 views

How reliable/portable are Nix built-ins/commands (echo, ps, sort, uniq) from Debian to other distros

I've coded a script and am wondering about it's reliability / portability. #!/bin/bash threadsPlease() { ps -mo lwp,c -p $1 | sort -gk 2 | uniq -f 1 } THREAD_LINE=$( threadsPlease $1 | grep -v - ...
1
vote
2answers
50 views

Job control over a Bash script

I have a Bash script of a thousand lines each containing an ffmpeg command. I start this with source script and it runs just fine. However, when I try to take control of this script in various ways, ...
0
votes
0answers
37 views

Passing variables through <<EOF [on hold]

fdisk /dev/$ROOTDISK <<PARTCMD d $ROOTPARTNUM n p $ROOTPARTNUM PARTCMD How can i pass the $ROOTPARTNUM variable?
1
vote
1answer
34 views

Pass shell variables to SQL statement

I want to pass shell variables to sql statement. Both shell script and SQL statement are present in the same script file. I want the values of the variables retMonth, retLastDay and retPrvYear in the ...
0
votes
0answers
17 views

How to display/change text in same window in yad

I wrote an application in Linux using YAD (shell script obviously). In my app when I click different buttons text in --text-info changes (should change). but as for now i could do it only by popping ...
0
votes
1answer
582 views

Bash script, ask for user input, to change a directory, sub directorys, and file's mtime atime linux recursively

Using GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) I am a bash scripting novice, not sure where to begin except at shebang #!. The following command. touch -a -m -t 201501010000.00 ...
1
vote
0answers
43 views

How to replace words in a string which has “|” in it [on hold]

For example line, in this loop in a shell script: for ((k=13;`awk -v f="$k" -F " " '{print $f}' line$i.txt` != "|";k++)) I want to replace the words in the line from 13th position until a "|" is ...
3
votes
2answers
45 views

process Count of each user in ps aux command

How can i create a script to count process run by each user in ps aux. I used this ps aux | awk '{print $1}' | grep root | wc -l but it lists count of root user only . I want to list number of ...
0
votes
3answers
56 views

Store CPU utilization into CSV file

OS: Debian 8 x64 I'd like to log every 5 seconds the CPU percentage into a CSV file in the format below: YYYY-MM-DD HH:MM:SS,CPU% I'm not familiar with how to use the top program to calculate the ...
4
votes
3answers
82 views

How to use call-by-reference on an argument in a bash function

I am trying to pass a "var name" to a function, have the function transform the value the variable with such "var name" contains and then be able to reference the transformed object by its original ...
5
votes
2answers
27k views

Cron job to delete files older than 3 days

I need to remove files older than 3 days with a cron job in 3 different directories. (these 3 directories are children of a parent directory /a/b/c/1 & /a/b/c/2 & /a/b/c/3) Can this be done ...
19
votes
4answers
31k views

Testing if a variable is empty in a shell script

I have seen the following technique used many times on many different shells, to test if a variable is empty: if [ "x$1" = "x" ]; then # Variable is empty fi Are there any advantages on using ...
2
votes
5answers
288 views

Get very next word of a substring in a string

I need to get the next word of a word in a string. I tried to write a script but it's not working. And it's good if you suggest me any other alternatives to achieve this. Script: #!/bin/bash ...
1
vote
2answers
65 views

Need output in a good format using shell script

I have a file, PoolReport.txt. Here is some sample data: Thu, Aug 27, 2015 7:56:29 AM PoolName,Total GB,Used GB ,Available GB ,Percent Full Oracle-RAID10,6432.539,6179.295,253.244,96.063 ...
3
votes
1answer
212 views

prevent a command from sending both stdout & stderr to any terminal or file [duplicate]

I would like to prevent my program from sending stdout and stderr to any terminals, files or devices. For this, I have three command crossing my mind, but I cannot distinguish their differences. Could ...
0
votes
2answers
37 views

Different behaviour of eval “ command \”$@\“ ”, “$@”, and “$(echo $@)” when used as arguments [duplicate]

I would like to pass multiple arguments to the Tor browser (firefox) programatically through a function arbitrarily entitled tor. This is so as to command tor search terms and voila! My search terms. ...
3
votes
2answers
44 views

How to skip unresponsive server

I wrote a script that runs on multiple servers. Sometimes the script gets hung on one of the servers and I have to hit (control C) to end the process. If not, it gets stuck and keeps trying to ...
2
votes
2answers
31 views

How can I send multiple options to one variable

I am running a loop for an array of variables that generates three more variables. i.e for foo in ${bar[@]}; do bar1=$(echo $foo | awk '{print$1}'); bar2=$(echo $foo | awk '{print$2}'); ...
1
vote
4answers
83 views

Last Working Day of the Month

#!/bin/bash #!/usr/local/bin #!/usr/sbin #!/usr/bin # Script to Check last working Day of the Month echo " Enter Month and Year :" read mon year cal $mon $year| egrep "28|29|30|31"|awk 'BEGIN { ...