Tagged Questions

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

learn more… | top users | synonyms (2)

1
vote
2answers
185 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
73 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
39 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
153 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
71 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
134 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
381 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
184 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
283 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
245 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
173 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
550 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
68 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
1answer
86 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
457 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
356 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
36 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
136 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
5k 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
77 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
1k 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 ...
2
votes
3answers
2k 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
37 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
211 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 ...
19
votes
2answers
3k 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
185 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
185 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
87 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
130 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 ...
1
vote
2answers
85 views

Copying latest files from the remote servers

We run report on multiple remote servers which we pick up monthly on our central server. The whole process is automated with scp and working well. The issue is that sometimes we go on individual ...
3
votes
2answers
275 views

Checking the status of custom services with a script

I have a handful of shell scripts that start WebLogic managed servers. I need to design a master script that does the following: Executes the shell script for a component\managed server Checks to ...
3
votes
5answers
134 views

Get values block by block in same file

I have a file say "SAMPLE.txt" with following content, P1 10,9:6/123456 P2 blah blah P1 10,9:5/98765 P2 blah blah P1 blah blah P2 I want a output file say "RESULT.txt" as, Value1:123456 ...
0
votes
1answer
94 views

Search a string between two timestamps starting from bottom of file

I was trying to find a string Cannot proceed: the cube has no data in huge test.txt file only between timestamps yesterday 22:30 pm to today 00:30 am. Script: tac test.txt | awk -v today=$(date ...
0
votes
1answer
48 views

Scripting error after bc command

I am trying to execute script contains the following: #!/bin/bash USED=`free -m | more | grep -v total | head -1 | cut -d':' -f2 | cut -d' ' -f18` CACHE=`free -m | more | grep -v Swap | tail -1 | cut ...
0
votes
0answers
35 views

shell script for executing mux verilog code

I have a verilog file mux.v and testbench muxTB.v. used ifdef caeses for behavioural model ifdef struct for structural model I have executed these files using the commands iverilog mux.v muxTB.v -D ...
0
votes
0answers
85 views

Specific Jar file doesn't run on startup

I want to run a jar at startup, so I asked a question here. I was given a few suggestions, so I started from trying to create a script file and desktop file. I created a script file and desktop file ...
1
vote
3answers
2k views

compare two columns of different files and print if it matches

I am using solaris 10 and Grep options involving -f doesnt work . I have two pipe separated files: file1: abc|123|BNY|apple| cab|234|cyx|orange| def|kumar|pki|bird| file 2 : abc|123| ...
0
votes
1answer
13 views

Renaming file in scripts [closed]

I want to rename IGNORE_NAMES_20140606-2014-06-06.txt file to IGNORE_NAMES_20140606.txt. I don't want to use the command below as I want to do it through a shell script. cp -p ...
0
votes
1answer
56 views

How to output the lines of a file after find and a grep?

Hello I want to output ERROR messages from logfiles from the current date. First I search for the logs of today with specific prefix: find /home/USER/logfilesError/ -maxdepth 1 -type f -name "xy_*" ...
0
votes
2answers
40 views

How can I search filenames which are starting with xy_* and are created/edited today?

Hello I´m currently trying to search for logfiles which are starting with xy_Number and are created/edited today(not last 24 hrs). I tried: find /home/USER/logfilesError/ -maxdepth 1 -type f ...
1
vote
1answer
253 views

Send copy of a script's output to a file

Say I have a Zsh script and that I would like to let it print output to STDOUT, but also copy (dump) its output to a file in disk. Moreover, the script starts with the following option set -o xtrace ...
2
votes
2answers
160 views

What is the best tool for automating the building 32-64bit libraries for Unix & Windows building C++ software, replicable by users and machines?

Is there a system or product that can be used in automating the process of building 32bit and 64bit libraries for multiple platforms (Solaris (Sparc & x86), and windows) used in building C++ based ...
1
vote
2answers
54 views

nested case - why must “;;” be put after possible commands and not directly behind “esac”?

I would like an explanation about the termination ;; in a nested case statement. Is it documented somewhere ? Why doesn't it work like this: #!/bin/ksh ... esac ;; ...
2
votes
4answers
194 views

Copy files and directory tree for filesize in specified range

Hi I would like to make a small script copying files from different directories example /pp/01 /pp/02/ etc... to another destination with the same directory design. But only those files within the ...
1
vote
1answer
2k views

-ksh: revenue_ext.ksh: not found [No such file or directory]

I am getting the same not found [No such file or directory] error when trying to execute a ksh script. Read tips about the PATH and running the script with a ./ in the posts here and here and tried ...
5
votes
2answers
108 views

How would I add a prefix to input I receive from a pipe via awk and color the prefix conditionally?

Is there a way to add a prefix to lines received (and filtered) via awk - yes I know that's possible so far - and then conditionally (e.g. based on the existence of the $PS1 variable of the ...
3
votes
5answers
150 views

Look if a folder has some files of certain extention

Lets say I have a file structure: $ cd /home/Desktop $ ls -d */ Abc/ Qwe/ Zxc/ Rty/ $ Now I want to iterate through every directory and look if they have any .pdf files. Could some one please ...
2
votes
2answers
931 views

How to get previous year and previous month in solaris 8

How to get previous year and previous month in solaris 8? I have tried below command but none of them is correct: date +'%m' -d 'last month' date +'%Y' -d 'last year'
1
vote
3answers
202 views

Brackets in if condition: why am I getting syntax errors without whitespace?

I am using the below script to move two days back when script runs at starting two days of the year and also check first and second days of every month and move two days back. if [$month="01"] ...