Shell Scripting

9K

Solutions

10

Articles & Videos

6K

Contributors

The term 'shell' refers to a general class of text-based command interpreters most often associated with the UNIX and Linux operating systems. Popular shells include Bourne, Debian Almquist (dash), Korn (ksh), Bourne Again (bash) and the C shell family (csh). Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin on Windows and emulate a full Unix environment with complete shell capabilities. Terminal emulators, such as xterm, GNOME Terminal and OS X Terminal, can be used to access shell.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi,
I am very new to shell scripting and i want to do following
read a xml file to extract value of <not_matched> tag,
from each of <SQL_Analysis>,<Data_Analysis>,<Graph_Analysis>,<Excel_Analysis>,<Pdf_Analysis> tags and compare it against a some value and depending on the result say Pass or Fail.

Any help much appreciated.

XML file as below :
<Execution_Stats>
      <Total_Executions>1</Total_Executions>      
      <Total_Errors>0</Total_Errors>
      <SQL_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </SQL_Analysis>
      <Data_Analysis>
            <NOT_COMPARED>0</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>1</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Data_Analysis>
      <Graph_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Graph_Analysis>
      <Excel_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Excel_Analysis>
      <Pdf_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Pdf_Analysis>
</Execution_Stats>
0
Free Tool: IP Lookup
LVL 8
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Hi all,

I need to know if 5000 computers on a list .csv are UP?

Which command can i use?

I have this but is for only one computer.

Test-Connection -BufferSize 32 -Count 1 -ComputerName 192.168.0.41 -Quiet

Can you help me?
0
I am running inotifywait to listen new files on a directory. The directory has 600 permission and user is vmail.
and I am running inotifywait using root user.

this is the command I used

inotifywait -mq -e CREATE --format %w%f /var/vmail/xxx/unsubscribe/cur | while read FILE; do echo "$FILE"; done

Whenever I receive mail it's not identifying the new file.
When I manually create file using root user it's displaying the file name.

What I observed is when I receive mail, the permissions of the file is 600.
When I create the file using root the file permission is 622.

I tried to switch user from root to vmail and run the command but no use.

I am stuck here.

I need to unsubscribe the user whenever I receive new unsubscribe mail immediately.
0
I have a issue where I want to have a shell script and change directories to remove a file.
For example;

1. Starting directory is /main/bin/scripts/ ( my shell script lives here ) removefile.sh
2. I want to change directories in the shell script and go to the level before main ( which is inputfiles/source/)
3. Need to locate a file and remove.

How can I do this? I've tried cd../../ but that doesn't work in the shell script.

Thanks
Jeff
0
I have a file with a character that translates into 272 when I do:
od -xc

The character looks like an A with a caret on top with a degree sign to the right. I am attaching an image of the character as well. I have tried sed, perl and tr and none of them are working.

For example:
sed -e 's/'$(echo "272")'/ /g' input_file > output_file

This does not work.

Any suggestions?
Image.jpg
0
script to ftp the txt files from windows to unix server automatically daily
0
How to stop and not kill a process
The .bat script bellow kills and don't stop my AlwaysUP.exe


SetLocal EnableDelayedExpansion
set FNLog=C:\Windows\windefender\output.txt
if exist "%FNLog%" (
  find "Finished" "%FNLog%"
  if !errorlevel! equ 0 taskkill /f /im AlwaysUp.exe /t
  ECHO del /q "%FNLog%"
)

Open in new window

0
in below code , it read all username from file users.txt with 1 word list word.txt .

now how can have multiple word file ? example word1.txt word2.txt ...

WORDS=word.txt
USERS=./users.txt

cat $USERS

while IFS= read -r USER
do
    echo "$USER `date`"
    time printf '1\n'$USER'\n'$WORDS'\n' | python Pulse.py 2>&1
    done < "$USERS"

Open in new window

0
I am creating a shell script to check if cron jobs are enabled/disabled and send a mail notification for the same (with job name).

#!/bin/sh

crontab -l > /app/file.txt
App_Home=/app
ctab='$APP_Home/file.txt'

while IFS= read -r value; do
entry=`$value | awk '{print $1}'`
echo $entry
if [[ $entry == "#" ]]
then
  echo " Entry $value is disabled "
elif [[ $entry == '#*' ]]
then
   echo " Entry $value is disabled "
else
   echo " Entry $value is enabled "
fi
done < $ctab

Open in new window


However, the above code is failing with the error message (#*: command not found).
0
every monday, we query the DB using sql statement with last week date. for example to query today 05/29 in db, i will use 2017-05-22 to 2017-05-26. Now i need a shell script to display & take last week dates automatically
0
Free Tool: Port Scanner
LVL 8
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Not quite sure if this is a good approach.  Looking at the last line of a file and then putting the 9 position into a variable.  The file is separated by commas.  It does not recognized the lastrec variable in the lastnum line.  


lastrec=$(awk 'END{print NR}' $f )  
lastnum=$(awk -F"," 'NR=="${lastrec}" {print $9}' $f )

thanks
bje
0
i have a start date variable like:
start=$(date +%d-%b-%Y %k:%M:%S")
stop=$(date +%d-%b-%Y %k:%M:%S")
how to find  stop-start in bash file
0
Hi all, im looking to import a large number of users in to AD, most of which will already exist

Is it possible to overwrite the current details with the mass import.

If so what would be the best solution

Thanks
0
Hi All,

I have a batch file on my local server that auto zips some daily files from a folder and then drops the zip file into another folder on the server, i used to have an ftp script that picked up the zip files and ftp them, however now our company has moved to sftp my script no longer works natively on windows 2008. so what i am looking to do is the following.

I need a script (powershell preferably) that search's the 3 folders where the zip files are dropped, pick up the zip file with a time stamp of the current day/date and sftp the files to a specific ftp folder. but not upload every zip file in the local folder.

Thanks for any help

Just for FYI i know there are applications out there but a script would be preferable as it should run under virtually no resources.
0
Hi Experts,

I am using below command to send file as body instead of attachment, I am able to do that but I want to send subject in french also.

cat french_characters.txt | mailx -s "RELEVÉ" -S ttycharset=iso-8859-1 -S sendcharsets=iso-8859-1 -S encoding=8bit email@email.com

This only send file as body in french charaters but not subject.

How do I do that?

Thanks in Advance.
0
We have a little program that runs an nmap against a few of our servers which is called testnmap.
We want to receive an alert if the service stops running.

Running the following gives the result of how many processes of this name are running.

ps -ef | grep -v grep | grep $service | wc -l

If the program is not running, it returns a 0. If it is running, it returns a 1.

However, if someone is running 'journalctl -u testnmap.service -f', this causes a second process to be found which means the results show 2. If the program has stopped running but a user is still running the above command, then we always have at least 1 as a result so cannot know if the program is still running or not.

Here are two results, one showing only the service running and the next showing the service running and someone using the journalctl command.

# ps -ef | grep -v grep | grep testnmap
root     24684     1  0 09:27 ?        00:00:00 /usr/local/testnmap/testnmap

# ps -ef | grep -v grep | grep testnmap
root     24684     1  0 09:27 ?        00:00:00 /usr/local/testnmap/testnmap
root     25448 24365  0 09:39 pts/1    00:00:00 journalctl -u testnmap.service -f

Can you rework this script to correctly work as needed.
Also, is there any way of preventing the script from sending notices more than once if the service is down since this is running as a cron job.

#!/bin/bash
service='testnmap'
if (( $(ps -ef | grep -v grep | grep $service | wc -l) < 1 ))
then
echo "$service …
0
I need a specific function just to calculate swap size as per ram like:

if ram < 2048 then swap should be 1.5 times
if ram > 2048 and ram < 16536 then swap size should be equal to ram
if ram > 16536 then swap size should be 16536

please help
0
Hi guys,

Although I find it hard to believe that what I'm looking for even exists, I'll still try my luck.

Is there any Linux Based IDE with native support for bash scripting?
(I don't only mean things like syntax highlighting but also auto completion and etc.) and preferably with git support.

Is there anyway to get a compiled bytecode from a bash script? I know about SHC but it doesn't really help becasue reversing it is way to easy - there's already a ready shell script to reverse the SHC compilation called UNSHC.
0
Hi all,

I need to parse http log file  to return each line where specific field is identical

The field to catch is that one just after the GET and which end by jpg  (The requested resource)

here is the file structure


2017-05-12 00:00:05 10.33.0.21 GET /image/_885385224_d.jpg - 80 - 141.101.88.155 Mozilla/5.0+(Linux;+Android+5.0.2;+SM-G530FZ+Build/LRX22G)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.132+Mobile+Safari/537.36 200 0 0 109
2017-05-12 00:00:05 10.33.0.21 GET /image/_872445004_d.jpg preset=l 80 - 172.68.65.13 Mozilla/5.0+(compatible;+bingbot/2.0;++http://www.bing.com/bingbot.htm) 404 0 0 15
2017-05-12 00:00:06 10.33.0.21 GET /image/_871332587_d.jpg preset=l 80 - 162.158.79.12 Mozilla/5.0+(compatible;+bingbot/2.0;++http://www.bing.com/bingbot.htm) 404 0 0 78
2017-05-12 00:00:07 10.33.0.21 GET /image/_811541689_d.jpg preset=l 80 - 108.162.246.120 Googlebot-Image/1.0 304 0 0 0
2017-05-12 00:00:07 10.33.0.21 GET /image/_873459194_d.jpg - 80 - 141.101.69.64 Dalvik/2.1.0+(Linux;+U;+Android+6.0.1;+SM-G935F+Build/MMB29K) 200 0 0 46
2017-05-12 00:00:07 10.33.0.21 GET /image/_722076749_d.jpg preset=l 80 - 162.158.106.37 Googlebot-Image/1.0 304 0 0 0
2017-05-12 00:00:07 10.33.0.21 GET /image/_864091284_d.jpg - 80 - 198.41.230.209 Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X+10_10_5)+AppleWebKit/602.2.14+(KHTML,+like+Gecko)+Version/10.0.1+Safari/602.2.14 200 0 0 78
2017-05-12 00:00:07 10.33.0.21 GET /image/_409007386_d.jpg - 80 - 198.41.230.197
0
Free Tool: ZipGrep
LVL 8
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

I am trying to find out if there is way to create a script to populate trusted site with all my sites instead of putting them in one at a time also create a script that will set all my setting for (custom level) and in the (Advance tab) in Internet Options.  Thanks
0
Hi all,

I have to  rename some files  as following

varnishSEO1-ddmmyyyy.log to varnishSEO2.log-yyyymmdd

Is there a rapid way to do this?

Thanks for your help
0
Experts,

All my existing servers that are monitored in Nagios are Linux. I now need to add a windows server to the below script.

My server is called backup.future.com and the entry in the uk-servers list is "backup.future.com:172.78.22.3"

#!/bin/bash
currDir=`pwd`
cat uk-servers.list | awk '

BEGIN {
        FS=":"
}
{
     name = $1
     ip = $2
     print "define host{"
     print "    use                             linux-server"
     print "    host_name                       " name
     print "    alias                           " name
     print "    address                         " ip
     print "    max_check_attempts              5"
     print "    check_period                    24x7"
     print "    notification_interval           30"
     print "    notification_period             24x7"
     print "}"
} '


for name in `cat uk-servers.list  | cut -f1 -d":" | grep backup`| 
do
        cat windows.services.template | sed -e "s/%CHANGE%/${name}/"
done

for name in `cat uk-servers.list  | cut -f1 -d":" | grep -v router`
do
        cat services.template | sed -e "s/%CHANGE%/${name}/"
done

membersAdmin=`cat uk-servers.list | grep future | cut -f1 -d":" | awk '{printf $0 ","}'`
cat hostgroups.template | sed -e "s/%GROUPNAME%/12-uk-admin/" | sed -e "s/%LONGNAME%/UK Admin/" | sed -e "s/%MEMBERS%/${membersAdmin}/

Open in new window

0
hello,

actually for all my script, on the code i import a csv file like that:

$csvFile = "D:\test.csv"
$create = Import-CSV $csvFile

or
import-csv "test.csv" | foreach .....

Open in new window


i need now to execute directly the script from powershell console and give the csv file name like this:

script.ps1 xxx.csv

can you help plz?
0
Hi all,

I need te nename some files from  file.log-ddmmyyyy to file.log-yyyymmdd.

Is there a rapid way to do this (sed,awk ...?)

Thanks
0
Hi all,

I need to split a big log file to some smallers logs files according to date in  original log file.

I want to create one logfile by date  an tar and zip it

each line from original logfile begin like this
[14/Apr/2017:15:31:21
[24/Apr/2017:09:32:27
[26/Apr/2017:10:071:49


I don't know ho to do this in bash.

Thank you for your help
0

Shell Scripting

9K

Solutions

10

Articles & Videos

6K

Contributors

The term 'shell' refers to a general class of text-based command interpreters most often associated with the UNIX and Linux operating systems. Popular shells include Bourne, Debian Almquist (dash), Korn (ksh), Bourne Again (bash) and the C shell family (csh). Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin on Windows and emulate a full Unix environment with complete shell capabilities. Terminal emulators, such as xterm, GNOME Terminal and OS X Terminal, can be used to access shell.