Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
15
votes
2answers
744 views
Is there something like JavaScript's “split()” in the shell?
It's very easy to use split() in JavaScript to break a string into an array.
What about shell script?
Say I want to do this:
$ script.sh var1_var2_var3
When the user give such string ...
0
votes
0answers
4 views
udev power_supply rules not triggering
I know this seems to be the most commonly asked question about udev on here, but I believe I've done everything correctly and yet my rules still never get triggered. The script is executable and works ...
0
votes
0answers
15 views
Convert a Column oriented file to CSV output using shell script
I have a file that come from map reduce output for the format below that needs conversion to CSV using shell script
25-MAY-15
04:20
Client
0000000010
127.0.0.1
PAY
ISO20022
PAIN000
100
1
CUST
API
...
2
votes
6answers
59 views
checking the largest number of a specific folder
Inside one of my folder I have a lot of files looks like enum-*
$ ls
PRIM enum-00020 enum-00040 enum-00059 enum-00078 enum-00101 enum-00122 enum-00141 enum-00160 enum-00179
...
1
vote
5answers
121 views
Avoid running the script if a variable is not defined
I have a script looks like:
c=0
for f in */*; do
cp -v "$f" "/myhome/CE$(printf '%0*d' 2 $BATCHNUM)-new-stuctures_extracted/test-$(printf '%0*d' 5 $c)"
c=$((c=c+1))
done
However, the user must ...
1
vote
1answer
24 views
Perl script is running fine in interactive shell but not as a cron job
I have installed dirvish for some backups. I have initialized one vault (host). And now I am using the following script to run it:
#!/bin/sh
/sbin/dirvish-expire --quiet && ...
0
votes
3answers
45 views
find most frequently occurring letter/character combinations in a file
find most frequently occurring letter/character combinations in a file
Instead of just looking for recurring words (a la: find n most frequent words in a file), I need to list all recurring letter ...
1
vote
1answer
789 views
How can I kill child processes with start-stop-daemon?
I'm writing a simple web server using nc and bash. It looks like this:
#!/bin/bash
rm -f /var/run/streamman/out
mkfifo /var/run/streamman/out
trap "rm -f /var/run/streamman/out" EXIT
while true
do
...
0
votes
2answers
39 views
Why this break can't get me out of this while-do loop?
code:
This is for creating some animation and when the count variable $i gets 5, it stops and carry on the future shell code.
chars="/-\|"
while :; do
for (( i=0; i<${#chars}; i++ )); do
...
1
vote
2answers
28 views
Select file based on number of lines and manipulate the result
I have a large number of files, all with the same format.
line 1: Gene ID
line 2: chromosomal position
line 3 - x: names of genetic variants)
I want to select only files containing at least 5 ...
0
votes
2answers
17 views
killing all the processes related to a script
I have a script that calls a lot of programs sequentially... How could I terminate this script once and for all? I know that I could click Ctrl+C to cancel some of the process but killing the whole ...
0
votes
1answer
18 views
I'm trying to write a script to compare results from a code to my already established results for regression testing
I've been trying to write a bash script to run my code, then compare the final output to a previous run (with the correct result) under regression.dat. The goal is for it to tell me if the code ...
2
votes
1answer
35 views
Thousand separator in awk
I would like to print thousand separator with awk's printf.
In bash, it is pretty straightforward:
> printf "a %'d b \n" 1234567
a 1,234,567 b
> LC_NUMERIC=fr_FR.utf8
> printf "a %'d b \n" ...
3
votes
5answers
6k views
How to rotate all images in a directory with imagemagic?
I want to rotate all the images in a directory that match a pattern.
So far I have:
for file in `ls /tmp/p/DSC*.JPG`; do
convert $file -rotate 90 file+'_rotated'.JPG
done
but that gives no ...
0
votes
0answers
9 views
PM2 inside bash script deployed by puppet not working
#!/bin/bash
yum -y install gcc-c++
wget https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz
tar -xvzf node-v0.12.7.tar.gz
cd node-v0.12.7
./configure
make
sudo make ...
13
votes
11answers
11k views
Decoding URL encoding (percent encoding)
I want to decode URL encoding, is there any built-in tool for doing this or could anyone provide me with a sed code that will do this?
I did search a bit through unix.stackexchange.com and on the ...
3
votes
2answers
40 views
Move a file and replace it by a symlink
Can someone give me a command that would:
move a file towards a new directory
and leave a symlink in its old location towards its new one
2
votes
2answers
17 views
Sub Shell Redirection Error With Variable ( while … ) $3 > $testdir/$testfile.log
My scripts executes the sub shell command along the lines of:
( while ..... ) $3>$testdir/$testfile.log
I get the error:
line 75: syntax error near unexpected token `$3'
line 75: ` ) ...
0
votes
1answer
32 views
Difference between two dates on Linux
I'm getting a date in the format of
v_date=$(date +"%Y%m%d" -d "1970-01-01 + $(stat -c '%Z' file ) secs")
v_sysdate=$(date +%Y%m%d)
echo "$v_date"
20150907
echo "$v_sysdate"
20150907
...
0
votes
1answer
588 views
CSH - How to check if input is NOT number
Please help, I can only see forums with this question for Bash, KSH, and others
Need to apply it on csh.
to check if the inputted $2 is not number nor the word "all"
if ($#argv == 2 && ($2 ...
2
votes
1answer
40 views
echo the created directory name
I'm trying to echo the new directory that I'm creating in the script.
BACKUP_DIR=`mkdir /tmp/"$TICKET_NUM"_EAR_BACKUP_"$(date "+%Y%m%d")"`
echo $BACKUP_DIR
But, the newly created directory is not ...
1
vote
1answer
717 views
LFTP mirror includes - including other directories other than what I've included
My question:
How can I make sure LFTP only includes files AND directories using --include or --include-glob, and not download a bunch of extra directories from the root of the remote that aren't in ...
0
votes
1answer
30 views
Raspberry Pi run script after startup
Hello I have a Raspberry Pi with openvpn installed and running perfect and I want to launch a command after the desktop mode enters and after all is loaded and running including openvpn on Raspbian. I ...
0
votes
1answer
20 views
I want to delete from particular words in all the line if that particular word is present
eg:
CREATE VIEW AIPKEYITEM.SEASONGROUPNETSALES (
CALENDARID ,
PRODUCTGROUPID FOR COLUMN PRDGRPID ,
NETSALESDOLLARS FOR COLUMN NETSA00001 ,
NETSALESUNITS FOR COLUMN NETSA00002 )
AS
SELECT
...
-1
votes
1answer
57 views
Convert hex decimal to decimal the string in shell script [on hold]
I have a file with a hexadecimal string.
I have delimeter like "65". If 65 comes in string, I need to check the next block, which is the length of blocks that I want to pick, and assign them to a ...
2
votes
1answer
21 views
System event on AC adapter insert or battery unplugged?
Does Ubuntu 15.04 (or maybe just Linux in general) have any sort of measurable event that fires when a laptop's AC power is disconnected and the unit flips over to battery power?
I would like to ...
2
votes
3answers
52 views
Delete Entries in File if the Same Entry Exists in a Master File
I have a JSON master config file whose value may be overwritten by a specific account's config file (also in JSON). The Master file has this structure:
{
"section1Configs": {
"setting01": ...
1
vote
2answers
30 views
Is there a command line spell to save specific columns by name in a CSV-file?
Suppose I have a crazy data set in CSV:
...
1
vote
2answers
26 views
List files in hierarchy of directory
I need to list files in hierarchy of directory. For that I wrote script like
foreach file ( * )
ls ${file}/*/*/*/*/*.root > ${file}.txt
end
But for this I have to know that in the directory ...
0
votes
2answers
42 views
Finding difference in dates which is in format “%Y%m%d%H%M%S”
I have a two dates in date +"%Y%m%d%H%M%S" format. How to find the difference and how to check whether the difference is more than 4 hours?
This is how i have tried
echo $(( ( $(date ...
0
votes
1answer
36 views
finding time of the file received in a directory on reading a filename [duplicate]
I read a file which have all the file names line by line which ($var) returns the file names in the directory /home/mydir .
input="/home/mydir/test/myfile"
while IFS= read -r var
do
...
0
votes
1answer
20 views
RRDtool update not working when integers and floats are mixed
I'm trying to store ADSL stats for my router.
I didn't do rrdtool info on the others beccause they are now showing the correct value after using the same command as in the script to update. The weird ...
3
votes
3answers
1k views
Query list of servers for memory/cpu allocated
Running RHEL 6.2, trying to write a bash script to SSH to a list of remote servers, and write the CPUs and Total Memory to a file, one line per host in the following format:
HOSTNAME1 CPUS: 12 ...
-1
votes
3answers
62 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 ...
2
votes
1answer
39 views
How can script execute itself via some exec again?
I'm making script for backing up data from server, it's gonna use ssh and scp many times. My private key is password-protected, but I'm using environment without any ssh agent.
I'd like to put ...
1
vote
2answers
34 views
Finding a file in a directory based on time
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 the file is whether in that directory for more than 4 hours.
I tried ...
1
vote
1answer
15 views
Storing integer values from string in rrd
I want to collect stats from my DSL modem every 10 minutes. According to lots of websites it's best to use rrd for this. My modem(TD-W8968) struggles with SNMP so I've made an expect script to pull ...
0
votes
1answer
38 views
Storage allocator out of space error on unix shell script
While running the script called abc.sh, following errors are thrown.
abc.sh: line 226: storage allocator out of space on 64946176 byte request ( region 64329285632 segments 1981 busy ...
4
votes
1answer
194 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
18 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
23 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
20 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
38 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
44 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
70 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
103 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
29 views
how to trigger sms from unix (shell script) [closed]
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
663 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
...