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

learn more… | top users | synonyms (2)

0
votes
1answer
30 views

script to zip a file and change its owenrship

I have a script I am working on that reads off of a text file and will use the information stored in the text file to put each line entered in as an array. This array is a reference to files that are ...
1
vote
1answer
81 views

Attachment missing in Unix mail when multiple files were attached

I am trying to attach multiple files in Unix, which are the result of a find command. When I try to send the mail, the attachments are missing. dir=$path echo "Entered into $spr/sum_master" for fil ...
-1
votes
3answers
75 views

Checking if line in file exist

I have a bash script which asks a user for the number of CPU cores and saves it to variable named $cores. Now I want to add this variable to .bashrc, so I ask user how much CPU cores he has and then ...
2
votes
1answer
54 views

shell script for mounting external device to mount point

I want to make a script to mount an external device to a particular mount point e.g say /mnt. Let me elaborate my question, suppose I run fdisk -l in terminal I would get this output Disk identifier: ...
-2
votes
1answer
32 views

Read file and do below command [closed]

From the 2 different web page the output goes to a single file called "traffic" From one page it always has a string "sqr" and from the other page it does not have the sqr string but "attach" I need ...
0
votes
4answers
80 views

Error: integer expression expected

I have written a script to determine the Load average on the server as follows: #!/bin/bash loadavg=`top -b -n1 | grep -i load | awk -F, '{print$4}'| awk -F: '{print $2}'` if [ "${loadavg}" -le 1 ...
0
votes
1answer
96 views

How to display a .jpg file using fbi in a bash script for set amount of time and then execute the next command in the script

I am trying to use fbi in a bash script to display a series of .jpg images. But once fbi begins its process, it continues to cycle through the images and I only want to display each image once for a ...
2
votes
3answers
79 views

Strange formatting of date in bash script

I am working on a script to sort my downloads folder by the date the files were created. This is the script I am using: #!/bin/bash cd ~/Downloads for FILENAME in * do if [[ -f $FILENAME ]]; ...
-1
votes
2answers
43 views

How to get `expr match` to extract colon-delimited key-value pair?

Given: myvar="present-value: 1", I'd expect expr match "$myvar" '\([0-9]\)' to output 1. However, instead it outputs blank and exits with a non-zero status code indicating no match. How can I get it ...
2
votes
1answer
94 views

Attach files for sending mail which are the result set of find command

By using find command I got multiple files. Now I want to add all these files as mail attachment. Please help me how to add these files as attachment in single mail. I want to implement this in ...
2
votes
2answers
55 views

bash function execution from command line

I love to play with bash script a lot. But I want to enhance the way I use bash script. I have a script(nepleaks.sh) as below used during my programming, ~ 1 clean(){ ...
0
votes
2answers
105 views

How to get the value from rows and columns from text file in bash?

I am working on a bash project. I need to get all the values (one at a time because I will be using them somewhere else) from a text file. The text file I will be getting is structured like this: ...
4
votes
2answers
67 views

Launching a terminal emulator without knowing which ones are installed

I need to write a script that will launch a terminal emulator and run a particular command in it. Since I don't know which terminal emulators have been installed on the target system, how could I find ...
0
votes
5answers
102 views

how to extract part of a filename before '.' or before extension

I have files in format below: abc_asdfjhdsf_dfksfj_12345678.csv hjjhk_hkjh_asd_asd_sd_98765498.csv hgh_nn_25342134.exe I want to get the value before the . and after the last _. The result would ...
3
votes
4answers
159 views

How to cut everthing until a specific word / after a find in a script

Hello I try to get the output of files from today wich contains ERROR. I use this to find the files I want: find /home/user/logfilesError/ -maxdepth 1 -type f -name "gandalf_*"\ -daystart -mtime ...
2
votes
3answers
68 views

Use awk results as parameters to another command

I'm extracting rows from a set of text files with awk. The files look like this: 1000 1 75 1000 2 76 1001 1 76 1001 2 80 I'm searching several directories of these with this ...
-1
votes
3answers
47 views

How can i make usage to print only once

#!/bin/bash usage () { echo "run with 1st argument -mux2 or mux4 or mux8 or default(mux2) or all ( all the 3 mux)" echo "2nd argument -struct or ifs or cases or asgn or ...
3
votes
1answer
65 views

Compose and pipe a gzipped tar archive in one go

I'm trying to come up with an effective way to create a gzipped archive of various system partitions on Android, piping everything out to stdout so as to be able to encrypt it as it comes across via ...
1
vote
3answers
424 views

Difference between ls -l and ll?

I'm relatively new to programming as a whole and some tutorials have been telling me to use ls -l to look at files in a directory and others have been saying ll. I know that ls is a short list, but ...
4
votes
1answer
160 views

Variable scope in while-read-loop on Solaris

    Could someone please explain to me why my while loop seems to have an internal scope? I've seen multiple explanations online but they all have to do with pipes. My code has ...
1
vote
1answer
60 views

Editing INI-like files with a script

I'm writing a script to automate setting up Puppet agent configuration files in Docker. Basically, I need to ensure that the following section is in /etc/puppet/puppet.conf: [agent] ...
5
votes
1answer
67 views

What else can break if I remove export from a variable?

My problem is that when I started coding my script I encountered several variable scope issues which resulted in the bad habit of exporting almost all my variables. Now that my code has got quite ...
-1
votes
1answer
35 views

How can I search for a user account in various sudo related config files?

I'm a scripting newbie...and I would like to search multiple servers for user ss7459 in the following files /etc/sudoers, /etc/sudoers.d/itse, /etc/sudoers.d/dbas and /etc/group. NOTE: The numbers ...
0
votes
1answer
118 views

How do I cat a command file?

I have the output of the crontab -l stored in a file (crontab_file) with no extension. But whenever I try to cat it, I get errors saying command not found for multiple line of the file. Here is the ...
1
vote
1answer
47 views

What priority should I give to a script running on startup?

I 'm running Angstrom distribution on an embedded device. I want to make use of its GPIO expansion ports, that are set to be high on start-up. Below, is the code segment, that releases an expansion ...
3
votes
2answers
102 views

Find files in directory with paired names

I'm running tests of a variable-size-and-contents test set. Data files are added and removed frequently. I'm looking for an automated way of gathering a file list. All files are in subdirectories of ...
28
votes
3answers
2k views

What does `{ { (exit 1); exit 1; }; }` mean?

I quoted the next code snippet from config.status generated by configure. if test ! -f "$as_myself"; then { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5 ...
4
votes
2answers
235 views

How to get the name of the user who executed a bash script as sudo?

I want to create a bash script that must be executed with sudo but should take into account the name of the non sudo user who executed it. So if user bob runs sudo ./myscript.sh I would like ...
3
votes
3answers
101 views

Is there some way I can start a (repeating) ping while the network is unreachable?

My ping command (on Debian 6 or 7) will repeatedly attempt to ping a server even while the network is down, if the network was up when it was started. Is there some way to start ping while the network ...
5
votes
2answers
243 views

Massively creating files with bash

I have been trying to figure this out tried different commands and still have gotten no where. Can you please help me with this question? In your home directory, create a subdirectory called shirts. ...
9
votes
2answers
121 views

Using a shell script as a virtual printer

I have a shell script that takes a PDF file as an argument and prints it with additional printer specific options. How can I add this script as a virtual printer that can be selected from the GUI? ...
4
votes
2answers
155 views

How do you correctly extract all command synopses from manpages in /usr/share/man/man1?

I'm trying to extract all command synopses from manpages in /usr/share/man/man1 using: #!/usr/bin/env bash ## synopses - extract all synopses in /usr/share/man/man1 cd /usr/share/man/man1 for i in ...
-6
votes
2answers
69 views

Shell script to compile C files

I used to have a shell script that would compile all of the FILE.c files in a directory to FILE.out I lost it and am trying to remake it and have the following which I know is very similar but can't ...
0
votes
3answers
59 views

Looping the listing files in UNIX

I've given the command: ls -lrt and the listed files and directories are: drwxr-xr-x 4 root root 4096 Feb 2 2014 abc drwxr-xr-x 4 root root 4096 Feb 2 2014 cde drwxr-xr-x 4 root ...
1
vote
0answers
35 views

Toggle Skype notification status

Being notified whether a contact appears online/offline or not can be changed via the Skype Options or via the ~/.skype/your_skype_id/config.xml. In this file, depending on what you chose, on can find ...
3
votes
3answers
157 views

AWK: Passing shell variables to awk

I am trying to pass a variable number of arguments from the shell script to a pattern recognition subset of a table. Here is my attempt so far: The file 'infile': ID,GROUP 1,GROUP2 ...
1
vote
1answer
104 views

script to send e-mail for success or failure

My Oracle backup sends out an e-mail with notification that backup completed and it was successful or failed depending upon it find some pattern. Our backup logs are getting very big - 14mg. Since ...
1
vote
1answer
33 views

Why sed wont remove my empty lines?

Can someone PLEASE explain to me why this sed command wont remove the empty lines? sed -e 's/\r//g' -e '/^{$/d' -e '/^}$/d' -e ':begin;$!N;/^state-text: {[[:space:]]\n/s/\n//;tbegin;P;D' -e ...
2
votes
1answer
73 views

Why is my tar in a script behaving different than using tar manually

I'm writing a backup script for my email and cloud service. For simplicity, I only posted the mail-backup part here. Basically, I have a Host-Machine with some Virtual Boxes running in it. These ...
3
votes
1answer
339 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 ...
1
vote
2answers
71 views

Copying the newest files

We have a script running which picks up the report generated monthly on remote servers. I was trying to find a way to pick up the latest file from the remote servers only. Will find work in script ...
1
vote
1answer
314 views

How can I ignore “zip warning: name not matched” when using zip command with -d option?

I am creating an sh file to run multiple commands in the background. At some line in this file, there is a command to update a zip file like: zip -d archive.zip file.txt This file.txt might not be ...
1
vote
3answers
160 views

awk for loop for each line in a file

I'm a newbie to bash scripting. I need help trying to figure out how to get loop through a text file and for every line take the fields of name , project #, and email, and replace them in a email ...
0
votes
2answers
27 views

Trim last chars from a line

I have a csv file and the lines have different length. But all of them ends with a number surrounded by a pair of braces. For example, ........{5} ........{16} I'd like to remove the number and the ...
1
vote
2answers
99 views

printing special characters in awk output

I have a large file that contains lot MQ messages with RFH2 header. Each message in the file is separated by a blank line. Now I need to split this large file into small files each containing single ...
18
votes
2answers
2k views

What is the difference between running “bash script.sh” and “./script.sh”?

If script.sh is just something typical like #!/bin/bash echo "Hello World!" Is there a preferred way to run the script? I think you first have to chmod it so it becomes executable?
2
votes
3answers
129 views

How to create a loop in bash script

I wrote the following script. It is invoked by udev. When I plug my external USB hard drive the script checks if the volume is mounted by truecrypt, if it is not, it mounts it; if it is mounted it ...
4
votes
3answers
127 views

Bash: Zipping/grouping files by common substring

I have about 100 files. They are named like this. 3000_ABCD_XXXXXXX.csv 3000_ABCD_YYYYYYY.csv 3000_ABCD_XYXYZYZ.csv 3000_EFGH_XXXXXXX.csv 3000_EFGH_YYYYYYY.csv 3000_EFGH_XYXYZYZ.csv ...
0
votes
1answer
36 views

How to turn verbose mode on and off using a case statement in UNIX

I'm trying to create a shell script file that uses getopts. The purpose of the program is to remove files that are in the project and place them in the deleted directory aka recycling bin. I have ...
2
votes
4answers
42 views

Generate multiple symbolic links with maitaining directory structure

I want to generate symbolic links from multiple folders with maintaining the directory structure. I read a few answers and the best thing i can come up with now is: find ...