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

learn more… | top users | synonyms (2)

0
votes
1answer
137 views

Recursively delete hidden directory & its files?

I want to delete all hidden directoris from a directory and its sub-directory. I also use rm -rf .directory_name this command is iterative command I want to a recursive command. Please anybody help ...
0
votes
2answers
728 views

Bash split a list of files

I have 200 files in a folder like: test_1_cfg.dat, test_2_cfg.dat,.... and so on. I need to include in a bash script the first 40 files as input and run some process, another script to read the next ...
0
votes
1answer
1k views

is there a “goto” like command in ksh

Here is my script: #!/bin/ksh #this is where I want to go again if user enter #an answer other than "yes or no" echo "yes or no?" read ans case $ans in [yY]*) echo "yes" ;; ...
0
votes
2answers
5k views

Shell scripting: -z and -n options with if

I have a shell script where we have following lines if [ -z "$xyz" ] and if [ -n "$abc" ], but I am not sure what their purpose is. Can anyone please explain?
0
votes
1answer
414 views

What is the purpose of xargs -I command?

I'm Unix noob, can you explain what this command does: files=(this_is_filename) for filename in ${files[@]}; do ls -t1 ../htory/$filename* | head -1 | xargs -I fname cp -p fname ...
0
votes
2answers
81 views

Executing a program according to the last modified date

I need to write a script which would execute some executables in a directory according to the last modified date. The oldest should run first. How do I do it? This is what I have done so far for f ...
0
votes
2answers
412 views

Functional shell scripting [closed]

I found out that when I want to create some shell script or advanced command it always made me trouble to remember the names of the commands and their switches. e.g. tr -d '\n' < file | wc -c ...
0
votes
1answer
87 views

Start script on boot up?

I want to run a script when the system starts. The script is: #!/bin/bash gnome-terminal --tab -t "MyPC" -e "sh -c 'nohup firefox & nohup gedit & bash'" --tab -t "MYPC2" -e "sh -c 'ls -al;ls; ...
0
votes
2answers
42 views

Using variable with awk -v in a shell script

I am modifying/re-writing some of the scripts written by former employees of my company and in one of the shell scripts I found the following line. b=`benchmark=30;grep "Waiting for timer" wk.txt | ...
0
votes
5answers
45 views

Is there a way to do a “full file buffering” inside a chain of piped commands?

Very often I do simple operations on a file, for example: cat file1.txt|sed -r 's/^ *//' to remove spaces at the beginning of the line. If I want to overwrite the file, the only way I know is: cat ...
0
votes
2answers
39 views

how to insert backslash at the front of # symbol?

In bash programming, given a variable, say varA, that store a string containing # symbol. Let's assume varA contain this value: ASD# 1, I need to append a backslash \ at the front of #, so the output ...
0
votes
4answers
275 views

keep the last file of every month and delete the rest

I have files like below. I want to keep SEP 30, OCT 30....files and delete the rest. Can you please help me with any script? -rw-r--r-- 1 nbswmcm advboprd 13463761 Sep 2 01:19 ...
0
votes
3answers
49 views

How to print loop index to a file using awk?

I'm a new in bash scripting. I need a help in how to print the loop index to a file using awk? Here is the code I used. echo "Write the start and end file number:" read sta end echo "$sta" "$end" for ...
0
votes
1answer
91 views

Bash error: “[y command not found” [duplicate]

I am trying to get this script to function correctly but I get ./passmark.sh line 7: [y command not found. Here is my script #!/bin/bash # A simple script to ask a user for a pass mark and then ...
0
votes
2answers
67 views

Bash Script using read needs to stop executing on Ctrl+D

I need to write a script that will add a line to a text file if Enter is pressed. But, if Ctrl+D is pressed, I need to exit that loop in the bash. touch texttest.txt LINE="0" while true; do read ...
0
votes
2answers
50 views

check two partitions by selecting random files and running sha1 hashes on two files of each partition

A previous answer to a post mentions to run sha1 hashes on an images of a dd drive clone image. Another answer to that post suggests mounting the dd image an then compare if the sha1 hashes of ...
0
votes
1answer
324 views

Launching a program and executing a command in bash script [closed]

How can I execute a command inside ROOT that I launch within the bash script? My aim is to have ROOT execute its GUI file browser and have it open if the user does not interfere with keyboard ...
0
votes
2answers
77 views

UNIX: Submit job only after previous job completes?

I would like to submit the same .sas job iterating over an argument, but I would like job only to be submitted after the previous is completed. Here is my attempt: #!/bin/ksh export weeks="1 ...
0
votes
2answers
1k views

How to run a command with a hidden password

I need to run a curl command that accesses a website that another person has the password to. e.g. curl --basic --user myfriendsname:friendspassword http://www.updateinfo.com I need a way where I ...
0
votes
2answers
3k views

Bash script returns “command not found” when outside the source folder

under my directory, /home/lucas/bin I have the following script term_multiscreen: [lucas@lucas-ThinkPad-W520]~$ sudo cat bin/term_multiscreen #!/bin/bash # Initializes ...
0
votes
1answer
116 views

Functions defined in .zshrc not found when running script

I have a function in .zshrc that mostly updates the PATH: my_function() { PATH=... } and some scripts that depend on it, e.g. my_script.sh starts with the following lines: my_function # do ...
0
votes
2answers
354 views

Bash: iterate with variable on the lines of `ls -1` output

In a simple cycle like the following for f in $(ls -1) ; do something done I would like to store each line of the output of ls -1 in the variable f. Is there a way to do this ...
0
votes
3answers
568 views

I want to create a zipped output file while keeping the original one

I am new to unix command and I have got one scenario that, I want to create a zipped output file while keeping the original one. I want to do it from Informatica end by using command task or session ...
0
votes
2answers
82 views

How to search '(+1)' character substring in a string

I want to search for (+1) in a string (which is a GDG dataset name to confirm if it is a GDG) and want to get a binary answer if it has (+1) as part of the string or not. Can some one please help?
0
votes
2answers
2k views

Are there any well known and well used shell scripting IDEs for Un*x?

Are there any IDEs targeted at shell scripting, specifically bash and zsh scripts? This means having syntax-highlighting for shell scripts and more importantly debugging environments with features ...
0
votes
1answer
146 views

I need Control loop help -

this is what I figured out in sorting an Array that has already had it's elements declared type int #!/bin/bash #sorting an "predeclared" array typeset -i store BigNum let store=0 BigNum=0 ...
0
votes
2answers
86 views

mount -a locks up my script if any of many remote drives are offline

I've written a backup script which backs up multiple windows servers by mapping those server's hard drives to the linux file system at a particular mount points. At the beginning of the script, I ...
0
votes
2answers
302 views

Making md5sum understand file names with spaces

I need to use md5sum in Python by using pipe to calculate checksum for a bunch of .mp3 files... is there a command which ignore whitespaces in filenames on the command line of md5sum program? For ...
0
votes
3answers
1k views

Script to login to ssh twice

I need to login through ssh twice with a script and can't get it to work. This is what I have in my script file: #!/usr/bin/expect set login "user" set addr "address1" set addr2 "address2" set pw ...
0
votes
3answers
174 views

Run two commands on same argument

I was wanting to maybe alias a command such that the command ran as per usual but also did something else on the argument/s before it was executed. An example might be: alias ls="echo displaying ...
0
votes
2answers
726 views

/dev/null-like automatic trash directory for file moves?

I can (redirect) textual output to /dev/null in order to get rid of it. This is quite handy because this way I can easily enable/disable it in my bash code. Now I have a script that processes files, ...
0
votes
2answers
344 views

I need to check a list of directories if it contains a directory newer than 1 month before now

Maybe the title is quite confusing so i'll try to explain what i have done until now. First of all i have build the list of directories i want to investigate with the code below: ...
0
votes
2answers
430 views

How to create as many variables as needed from shell script(bash)?

I'm making a script for monitoring some user processes with Upstart but, since its for the company I work for, they asked me to do it generic...how's so? Well, the number of processes being monitored ...
0
votes
2answers
269 views

read file record by record and do transformation to the subsequent record based on above record and write into another file

Data file is fixed length file, and I want to read the file record by record and do transformations to the subsequent records based on the prior records (and write the results into another file). ...
0
votes
2answers
373 views

How to make any file and put contents in that using script

I want to modify configure.sh to create a file /etc/pam.d/XXX with some predefined content. How can I do this by putting the file's absolute path and content in configure.sh? Please explain the ...
0
votes
1answer
12k views

bash script that print cpu usage,diskusage,ram usage

As we know that for sysadmins uses commands top for cpu usage, free -m for memory, df -lh for hdd space. I want to cut just usage details of cpu, memory, and Hdd. I need to make three commands and ...
0
votes
2answers
171 views

file command + how to view all results from file command

I use the file command in order to verify if file (PATH) is text/ascii file or encrypted file Because file command have allot of results ( small example in example 1 ) I want to get the all ...
0
votes
2answers
2k views

Deleting many files except one type [duplicate]

Possible Duplicate: Deleting all files in a folder except files X, Y, and Z I am writing a script to compile many .tex files. After that, many auxiliaries files were created. So, I would ...
0
votes
1answer
251 views

How to automatically install packages?

I want to install packages automatically by running a script I can write yum install php, but I want it to install another package once installation of the php package is completed. Is there any ...
0
votes
1answer
221 views

The “cp p2 &2 &” command makes Konsole to disappear, is it a bug?

The goal is start a background process that copies the data from the pipe p2 to the STDOUT as p2 is feed with data by some other process. I guess the command is incorrect. Nevertheless, the Konsole ...
0
votes
3answers
10k views

How do I redirect command output to a file?

I have a command that I run in a folder that outputs MD5 hashes and filenames on the terminal: ls |sort -nr | xargs md5sum I need this output in a text file that I can download and compare to ...
0
votes
1answer
32 views

Bash Script Not changing Directory

I have a small script I am working on where I need to read in a few Strings: #!/bin/bash echo "Enter SUID: " read $uid echo "Enter Tag Number: " read $dicomTag dicomDump() { arg1=$1 ...
0
votes
2answers
52 views

Command to see if a word is in a list of files and output how many files it is in

There is a similar question to mine already but mine has a slight difference. I want to see how many files contain each word. When a file has a word then it increments the counter and then continues ...
0
votes
2answers
48 views

How do run MYSQL scripts from a shell script with bash variables?

Im making a script where I connect to a database, look for a value and then if that value returned something then I will do something else. ip=$("variable is defined here") Then I connect to the ...
0
votes
2answers
55 views

How to list files and directories of a mount point

Given a mountpoint such as /dev/sda1 how can I list the contents of this file system using shell script. My objective is to delete the oldest file in this drive.
0
votes
1answer
47 views

crontab not executing my script?

I added this rule to the bottom of my crontab * * * * * /root/test.sh It basically resets iptables so I can fool around. If I mess up I won't be locked out of my box. When I run the script in bash ...
0
votes
2answers
113 views

Constantly check if file is modified bash

I have a file called file1 I want in a script, whenever there is a change in it, do something, a beep sound actually. How do I do that ¿? Thank you in advance
0
votes
1answer
72 views

Grep -m 1 doesn't work

I'm using the following command to parse a form element from HTML using grep. The $RESP variable contains the output from a previous curl request ... echo $RESP | grep -m 1 -o -E 'name="id" ...
0
votes
1answer
34 views

evaluating a string in csh

script1 is as follows #!/bin/csh echo $* $* Then I run the following on command line: >script1 setenv VAR "/user/path" \; ls It gives output as: setenv VAR /user/path ; ls setenv: Too many ...
0
votes
1answer
83 views

Very basic H/W question using pipe and grep

I have two text files, F1a.txt and F1b.txt, with essentially the same data: the driver's surname and their nationality. For example: Hamilton GBR Alonso SPA I have concatenated these ...