Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
1
vote
1answer
19 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
...
0
votes
0answers
14 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
30 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
85 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 ...
-2
votes
2answers
49 views
Writing Short Shell Script Program [on hold]
I was going through past paper exam questions on Unix and realized I'm pretty clueless when it comes to writing a short shell script program. I've done a few but not to the extent of this past paper ...
1
vote
1answer
30 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
38 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
93 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
63 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
46 views
operator in if condition
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"] ...
1
vote
1answer
40 views
case multi-pattern with strings
If a put "TITI" or "TETE" on V3 it doesn't work but "TOTO" will work. It's like it takes into account only the first possibility..."TOTO".
#! /bin/ksh -
V1=CRITICAL
V2=HARD ...
-3
votes
0answers
27 views
writing a shell script to generate new files that contain the data with the same date only
Create a file with the name “Q2_data.csv” with the content
Date,Interface_Name,Traffic_Incoming,Traffic_Outgoing
01-05-14,SHTCE1_SHTCE2,112233,332211
02-05-14,SHTCE1_SHTCE2,212233,432211
...
-2
votes
0answers
30 views
cannot set data in xml array with sed [on hold]
i'm parsing an xml file with XMLStarlet ; then i need to set that data in an xml array into another xml file . the problem is that i didn't get the data on my final xml.
i notice that i'm using sed ...
1
vote
1answer
28 views
Does the command execute automatically when setting it to a variable?
I'm getting familiar with all about linux & shell/bash scrpiting.
I'm configuring a backup script & it will compress an entire dir.
I wanna know if I have to print the variable where a put ...
1
vote
2answers
58 views
can you only input the password once and then execute the su command without entering a password? [duplicate]
I am copying files from a remote server to my local server. Here is the code that does this:
sshpass -p "password" ssh -q username@$192.168.162.156 "mkdir -p /temp ;
...
1
vote
1answer
31 views
Using kornshell or Perl to circumvent permissions needed by root
I have a problem where I need to change the ownership and permissions of one file that exists on more than 200 servers. I belong to 2 different groups and need to change the ownership from one group ...
0
votes
3answers
79 views
compare two files based on a column and print it
I have two big files of 400,000 lines. I want to compare the column 1 of the second file with column 1 of first file recursively. If they match I would like to print the whole line. It is a sorted ...
1
vote
2answers
24 views
Shell script to Capture the file name and size in csv file and add header on that file
I have a number of zip files in a certain folder. I want to capture file name and the size of the files in a CSV format in day wise and put it in crontab so I can report on a daily basis, and then ...
-1
votes
0answers
17 views
How to return back to the loop after connecting from server1 to server2 in unix?
I'm having a csv file which has details like filename,path,file typefilesize,owner. I need to read the filename from csv file and copy that file from its own server to other server say(server1 to ...
2
votes
2answers
112 views
Any way in Bash to write to a file every X seconds without closing it?
The hardware watchdog on my system needs a 0 written to /dev/watchdog at less than 60 seconds interval or it will fire. The file handle must be kept open however or the watchdog is then disabled.
...
4
votes
2answers
103 views
How exactly does `if $cmd ; then $cmd ; fi` differ from `$cmd && $cmd`?
In an answer to another very good question I made the following assertion:
According to my reading of the POSIX specs, the use of one or the other makes no difference from a parsing standpoint.
...
8
votes
4answers
718 views
Bash syntax error when “else” follows an empty “then” clause
Why would following script not execute, but give a syntax error of else:
LOGS3_DIR=~/logs
if [ -d "$LOGS3_DIR" ]; then
cd
cd "$LOGS3_DIR"
echo "$LOGS3_DIR"
for filename in `find "." -mtime 1 ...
1
vote
1answer
13 views
Sourcing scripts with a for loop for different variables
I have several shell scripts that I summarised within a global script. I am using some variables that are the same across all scripts, and I wrote a separate script for this, which I am sourcing in ...
3
votes
1answer
27 views
Redistributable completion for my bash scripts
Is there a simple way to embed the completion features inside a script, for bash ?
I have a script that I want to redistribute, but I can't ask the people to add something inside their ...
3
votes
2answers
90 views
Read all files in folder and subfolders - progress and size
Command I have is:
time find . -type f -print -exec cp {} /dev/null \;
This command finds all files in current folder and subfolders, print the name of each file and copy each of them to /dev/null. ...
-1
votes
1answer
35 views
Cron spamming because of renice [on hold]
I have a bash script that I execute using cron.
The script begins like this:
#! /bin/bash
DIR=/home/pi/bin/run
renice 19 -p $$
ionice -c 3 -p $$
:
Now, every time cron runs this script it sends ...
0
votes
1answer
31 views
Writing a shell script in Ubuntu to process several layers as a single animated GIF file [duplicate]
I am an Ubuntu 12.04.4 LTS 32-bit user and I would like to automate the process of opening several PNG images as layers then saving these layers as a single animated GIF file in the GUI of GIMP. My ...
4
votes
2answers
81 views
Remove specific file from directory if it's the only one
I have a lot of directories and sub-directories. I want to recursively remove one specific file from a directory if it's the only one there. Also assume that there are no sub-directories in that ...
1
vote
1answer
55 views
Shell script and crontab to capture file size, name and date in a CSV file and then send via email?
I have a number of zip files in a certain folder. I want to capture file name and the size of the files in a CSV format in day wise and put it in crontab so I can report on a daily basis, and then ...
3
votes
2answers
26 views
Have ssh-add be quiet if key already there
I want to put ssh-add /path/to/special_key at the top of a script. This works fine, but it always prompts for the passphrase. This is strange, and a little annoying, as it still asks for the ...
1
vote
4answers
76 views
Add/delete workstation ip to /etc/sysconfig/iptables and then run service iptables reload
I need a script to add a users workstation ip to /etc/sysconfig/iptables and then run a service iptables reload. I need the same type of script for removing this rule from iptables.
I found the ...
1
vote
1answer
30 views
Copy the file created newly in UNIX [closed]
I have a directory where so many files created daily and need to copy the new files which were generated. And all files will be created with starting name abc_
Ex:I have a file abc_0520123.pdf on ...
2
votes
1answer
31 views
Sharing variables across multiple shell scripts
I am trying to summarize multiple shell scripts within one large shell script, such as this:
#!/bin/sh
bash script1.sh
bash script2.sh
bash script3.sh
All scripts share the same variables "var" and ...
0
votes
1answer
39 views
two .csv files compare using awk
I need to compare two files, File1.csv and File2.csv (Separated by ',') using Awk
Logic:
Column PID in both files are reference.
If for same 'PID' in 'File1.csv' and 'File2.csv' and in both files ...
2
votes
3answers
111 views
How do I drop root privileges in shell scripts?
The "--up" option in OpenVPN is normally used for routing etc. And so it is processed before OpenVPN drops root privileges to run as nobody. However, I am invoking shell scripts that need to run as an ...
0
votes
2answers
33 views
Simple Script to setenv tcsh or export bash
I am having problems with simple scripting, my Box is CentOS so bash is the default shell, now I wanted to send a line via setenv (tcsh) and would like to make a script that will ask me to input a ...
2
votes
4answers
158 views
how can we use `awk` to get multiple words after a significant word?
I want to connect to my DB only once to do multiple SELECT queries as follows:
#!/bin/bash
#Begin Code
query=$(echo "SELECT COUNT(*) from USER_IPTable;
SELECT User from USER_IPTable;
...
-8
votes
1answer
42 views
I need a certain script [closed]
Ok lets say I have a list of servers in a text document going user:pass:Ip, I need a script that will log into those servers and execute a command. So for instance ./Script servers.txt
where ...
1
vote
1answer
87 views
Switch users with sudo or su in a shell script
I inherited this. Long story short I have an XML file that is calling a shell to run some commands. Everything I have tried has failed at the second su in the script. Here are some of the failure ...
2
votes
3answers
83 views
grep on a Java Method
Lets say I have a java class called DirectAction
some of the methods in the class have the word "action" or "Action"
What is the grep command to get the names of all the methods who have "Action" or ...
5
votes
3answers
285 views
Prompt user to login as root when running a shell script
The problem I am getting is, when I enter the command,
su - root
at the beginning of my shell script file, it prompts the user to enter the password and then does NOT continue with the rest of the ...
5
votes
2answers
126 views
What does ${3#?} do?
I have a script with the following variable assignment:
TEST_VARIABLE=${3#?}
What does the ${3#?} do?
1
vote
2answers
49 views
Run jar on startup in all *nix based systems
I have a jar file which I need to run at startup in all distros of Linux. My previous question here, gave me an idea a rough idea on X-servers. Since I wasn't able to perform startup, I moved on to ...
0
votes
2answers
44 views
SSH using diff and still not working
I have 2 file, a.txt and b.txt and I want to compare them.
a.txt contains:
abc
jkl < jkl
mno > mno
pqr <> pqr
b.txt contains:
abc
jkl < jkl
mno > mno
pqr <> pqrs
stu
I'm ...
1
vote
4answers
74 views
How do i get the latest file from a list of files in a particular directory
I need to get the latest file from a list of files in a particular directory.
When I run the script the first time I've copied the list of files in a particular directory to another directory.
From ...
2
votes
2answers
119 views
Header function with increasing number in bash
I would like to have a function in bash that I can use in some install scripts to announce that the next paragraph is starting.
A simple solution (with colors) would be
headline(){
echo -e ...
1
vote
0answers
9 views
Changing KDE's mouse theme and buttons settings from a shell script
I'm trying left handed mousing, and I want to be able to easily switch between right handed mode and left handed mode. There is a utility for Windows called SwapMouseButtons that allows to bind a key ...
6
votes
10answers
419 views
Copy only Specific text of a file to another
I have a file abc.txt the contents are
<classpathentry kind="src" path="Sources"/>
<classpathentry kind="con" path="WOFramework/ERExtensions"/>
<classpathentry kind="con" ...
0
votes
2answers
43 views
shell or python script to transpose rows to columns [duplicate]
I have a big file with numbers like:
1 2 3 4
5 6 7 8
9 9 9 9
I want to tranpose it into
1 5 9
2 6 9
3 7 9
4 8 9
I have search on google for solutions,
but those solutions simply don't ...
8
votes
1answer
286 views
communication between multiple processes
I have a bash script, which runs manager() function as a separate process for x-times. How is it possible to forward messages to all manager() processes from within the script?
I've read about ...