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

learn more… | top users | synonyms (2)

1
vote
2answers
107 views

renaming a directory and its subdirs without affecting their files

I have to rename directories under the root directory with prefix "ms_PF" and then rename their subdirectories with the modified name of the main directory with an extra "_", and then copy all ...
2
votes
2answers
2k views

How do I use an If-Else query based on the day of the week?

Problem: I need to check if today is Thursday and perform different actions based on the result of this condition. I tried two different approaches: Getting the Day Name: DAYOFWEEK=$(date +"%a") ...
5
votes
2answers
170 views

[ vs [[ : which one to use in bash scripts? [duplicate]

The zsh man page, in its section on test (aka [), explicitly advises against using it at all, and urges readers to use [[ whenever possible. The relevant section states: The command attempts to ...
3
votes
2answers
145 views

Concatenate block of lines with following block of lines

I am trying to process some text exported from lecture slides using pdf2text. The bullet points of some slides show up like this: title for the list - - - a bullet point text another bullet point ...
2
votes
3answers
3k views

Bash script; optimization of processing speed

I was wondering if there are general guidelines for optimizing bash script. a) For example, it is more convenient to write loops than lines of commands, but is it also faster to process for the ...
4
votes
3answers
625 views

Linux command line that will fail if any standard out is produced

Is there a simple utility which I can pipe output to on Linux that will: Return a success code if there is no output on standard out (and / or standard error). Return a failure code if output is ...
13
votes
3answers
5k views

How can one run multiple programs in the background with single command?

How can one run multiple programs in the background with single command? I have tried the commands below, but they do not work. nohup ./script1.sh & && nohup ./script2.sh & -bash: ...
2
votes
1answer
180 views

Difference between two types of shell arithmetic

What is the difference between the following two shell arithmetic commands: echo $[ $var1 - 1 ] echo $(( $var1 - 1 )) Assuming var1 = 5 for example.
2
votes
3answers
989 views

What's the best way to backup files via network on Linux and Solaris machines?

I wonder what the best way to backup files VIA network I have Solaris machines with Oracle 10i with VERITAS cluster, machines are connected to EMC storage /data/oracle directory is mounted on the ...
2
votes
1answer
3k views

Users home path in a bash script

I'm writing a bash-script that will be run as a cron job everyday. Very basic, I was wanting to change the wallpaper daily. I have mint-14 with mate. The thing I'm getting caught up on right now ...
-1
votes
2answers
4k views

Bash -Extract characters from string

Suppose I have the following variable $string = 'cat somecommandhere' Now the output of the above cat command is test="Thanks serverfault" I want to extract the value between the quotes and ...
2
votes
1answer
6k views

error handling in expect?

I am just improving my quetion becasue i have acieved so far upto this: set username [lindex $argv 0] set password [lindex $argv 1] set hostname [lindex $argv 2] if {[llength $argv] == 0} { ...
2
votes
1answer
2k views

Create sub-directories and organize files by date

I have some directories of files copied from my security camera that I would like to organize into sub-directories by file date. So for example; -rwxrwxrwx 0 root root 4935241 Jul 19 2012 ...
2
votes
2answers
636 views

How to pass the output of a script to a command like ls without the output being split?

Suppose I have a script like this: #!/bin/bash printf '%q\n' "b c" Executing the script prints: b\ c on the commandline. Now, being in a directory which contains a file named b c I want to pass ...
1
vote
1answer
303 views

Is there some sort of “no newline at eof” rules for bash scripts?

I have two files, an env file and a run file. When I deploy them to my Ubuntu Server box I get the error: ./start-admin: line 10: syntax error: unexpected end of file If I deploy and then add a ...
2
votes
1answer
127 views

how do i suppress seds unnessary output while using option -e?

why n option is not working here [root@testgfs2 final]# echo a b c | sed -ne 's/[[:blank:]]/"/gp' -ne 's/^/"/pg' -ne 's/$/"/pg' a"b"c "a"b"c "a"b"c" i just need : "a"b"c" actually ...
2
votes
2answers
348 views

changing pattern by removing spaces?

file : hi hello,new york, , ,brazil site ,brazil january,month is feb , , ,indiana jones task: delete all horizontal space (spaces and tab) between any two comas (like , ,) if ...
0
votes
1answer
135 views

Package Installation log creation

I have written a script for installing packages on Linux(Ubuntu). So I want to create a log file for installation of packages for troubleshooting if any problem occur during installation.So please ...
1
vote
1answer
577 views

How to ssh on multiple ipaddress and get the output and error on the local *nix machine?

command="ls -lrt;uname -a;uname -o" for i in 10.38.227.229 10.38.164.103 do ssh auto21@$i "$command 2>&1" >> log #ssh -n auto21@$i "$command" 2> >> log done i am trying ...
7
votes
1answer
3k views

SSH causes while loop to stop

I have finally managed to boil down a problem I have been struggling with for a few weeks. I use SSH with "authorized keys" to run commands remotely. All is fine except when I do it in a while loop. ...
0
votes
1answer
243 views

Moving Same files from different folders using shell script on AIX 5.4

There are two folders named Folder1 and Folder2. Folder1 has files with name:For example S-080001-0-0.xml with its corresponding same files in Folder2 named S-080001-0-0.xml The change in Folder2 is ...
6
votes
2answers
735 views

Find all files with a Python Shebang

I'm trying to run a PEP8 check against a large source tree. The tree is comprised of a mix of files in various languages. The idea is to check all the Python scripts without having to explicitly list ...
2
votes
1answer
309 views

shell variable in awk is not being passed to all the lines but just for the very first line of input?

inputfile:is2.txt 10.39.5.41,A1,B1 10.39.5.41,A2,B2 10.39.5.41,A3,B3 10.39.5.41,A4,B4 10.39.5.41,A5,B5 10.39.5.41,A6,B6 script : #!/bin/bash second_column="OOOOOOO" # OOOOOOO will be added to ...
1
vote
2answers
407 views

reading from a file and changing its pattern into an array?

I have a CSV file containging entries like this : ipaddress,VLAN,VLANid 10.192.168.1,vlan-xyz,3 10.192.168.1,vlan-abc,8 10.192.168.1,vlan-mnp,11 10.192.163.24,vlan-llz,3 10.192.163.24,vlan-bbz,5 ...
1
vote
3answers
6k views

Print given number in reverse order

clear echo "Enter a number" read n sd=0 rev=0 while [ $n -gt 0 ] do sd=$(( $n % 10 )) rev=$(( $rev *\ 10 + $sd )) n=$(( $n / 10 )) done echo "Reverse number of entered digit is $rev" ...
1
vote
1answer
987 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 ...
1
vote
2answers
211 views

Automation of openldap installation

In my group we often install ldap on new servers. We have two different configurations currently. A mirrored configuration and just a regular standalone configuration. The installation process gets ...
0
votes
1answer
140 views

How to safely enlarge a gzipped file?

I have a gzipped file (around 3Kb), and I want its size to be exactly 4000. To achieve this goal, is it safe to add trailing padding with zeroes? (By safe I mean that the content of the gzipped file ...
1
vote
2answers
567 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 ...
1
vote
3answers
477 views

Reading a directory in shell script

I want to read a numbered directory which is under a path, into a variable in shell script. The paths are something like this: .../releases/R1/... .../releases/R2/... .../releases/R3/... Each time ...
0
votes
1answer
264 views

Solaris 10, Shell Script, Cursor movement [closed]

#include <signal.h> #include <unistd.h> #include <stdio.h> #include <sys/types.h> #include <time.h> void prtime() { time_t rawtime; struct tm * ...
7
votes
4answers
2k views

redirect and log script output

I am trying to tidy up the following snippets, design goals are to log all output from a script, and should not be a wrapper. Less lines are better. I don't care about user inputs (at this stage), ...
0
votes
1answer
257 views

zmodem not working without minicom

I want to upload and download file from and to the target board. I am able to send the file from the target board to PC using zmodem protocol to be specific using command sz -vv -b filename > ...
-2
votes
3answers
500 views

Find files with similar names in a folder using shell script

I have a requirement of selecting xml files from a folder of same ID's. E.g. There are files with name S-000001-0-0.xml S-000001-0-1.xml S-000001-0-2.xml S-000001-0-3.xml S-000001-0-4.xml ...
0
votes
1answer
2k views

How to parse XML to CSV with a shell script?

What is the ideal way to parse an .xml file into a .csv file that I could include with my shell scripts. I know bash cant do it but I'm unsure if I should try in awk or sed. I imagine a language ...
0
votes
2answers
228 views

Shell script parameter substitution

I have seen a line of shell script as follows: local soft_upgrade=${3:-false} What does this mean? I don't know what 3:-false means.
6
votes
2answers
386 views

Why does set -e not work inside () ||

I've run across some scripting like this recently: ( set -e ; do-stuff; do-more-stuff; ) || echo failed This looks fine to me, but it does not work! The set -e does not apply, when you add the ||. ...
8
votes
4answers
11k views

How do I append text to the beginning and end of multiple text files in Bash?

I have a directory full of text files. My goal is to append text to the beginning and end of all of them. The text that goes at the beginning and end is the same for each file. Based on code I got ...
1
vote
2answers
146 views

sed pattern matching with deletion over a line

I want to delete only some spaces(say 4) after the line$#*425 with space I am not able to complete it please suggest echo "line$#*425 with space " | sed 's/ /\1 \2/g' i am thinking of ...
1
vote
1answer
144 views

Copy files excluding x,y,z causing error in shell script

I'm not well versed in shell scripting but I imagine this to be a painfully easy fix but its eluding me. I need to copy the contents of a directory excluding a number of files. I have a command that ...
1
vote
2answers
98 views

how obtain directory files info

I have the need to get information about a specific directory, basically I need to know the correlation between small, medium and big files. I came up with this: for i in K M G; do printf $i du ...
1
vote
2answers
2k views

case + how to implement equal or less or greater in case syntax

My target is to verify a range of number with (only with case + esac), and print the range. So for example: If the number is between 0 and 80, print >=0<=80 If the number is between 81 and 100 ...
1
vote
1answer
1k views

File is readable by everyone, but I can't open the file

I'm fairly new to Unix and I have written a script: SERVER="/usr/local/abc/.../somefile.txt" OPTION="$1" if [ x$OPTION = "xtitle" ] then grep $OPTION $SERVER exit fi As far as I ...
9
votes
5answers
11k views

Binary to hexadecimal and decimal in a shell script

I have a context where I need to convert binary to hexadecimal and decimal and viceversa in a shell script. Can someone suggest me a tool for this?
1
vote
1answer
475 views

Running a script as Grub boot option

I'm assembling some DR stuff for my Linux boxes. One item that would be really handy would be a GRUB option that would run a script to change my boxes from static IPs to dynamic. I know we could do ...
2
votes
1answer
603 views

How to wait for a subprocess used for I/O redirection?

Consider the following snippet of Bash script: exec 3> >(sleep 1; echo "$BASHPID: here") do-something-interesting exec 3>&- wait $! echo "$BASHPID: there" When executed, it produces: ...
-1
votes
3answers
2k views

How to run a shell script with export command in crontab

I have a shell script that exports values of variables when executed. The same values will be used in another script. How to run this script(test.sh) in cron. #!/bin/sh export I="10" echo $I I will ...
1
vote
1answer
262 views

Cannot enter in centOS with any user

I am using cent OS Operating system without GNOME. In the starting, it asks localhost login: Password: It has one user named service under group name service whose password is also service. I ...
2
votes
1answer
303 views

bash scripting add arguments

I have created a script which takes parameters and arguments. I want to insert the --help argument. I already know how to parse normal arguments with -, but I don't know how to parse the -- ones. to ...
2
votes
1answer
2k views

Bash vs ksh pipes

I am stuck with some problems with my scripts in ksh. FWIW the problem which I am unable to overcome is that when I use a structure such as this command | while read VAR1 do many.commands using ...