Improve company productivity with a Business Account.Sign Up


Shell Scripting





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 all,
I have a zonelist.txt file

In the file the contents are standard forward and reverse zones.  For example

I would like a bash or a shell script that uses dig to transfer each of the contents into individual files based on the zone and put them into a folder called transfer.

For example if I do a list in that folder I would have individual flies. For example

I use a Mac and I thought I could use
dig @ -f zonelist.txt

But that just shows them on screen and not in individual files.

Lastly. Is any zone transfer is refused or failes and or for any reason it does not get that zone to make a file called errors.txt
Get your problem seen by more experts
LVL 12
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

How can I get a list of packages available for update on RedHat (using yum) and put the package list in a file for later use?

Basically I would like to be able to remove from the list a few names with a BASH script and then perform a yum update using the updated list.
My input format is log1.txt .which contains below information.

Input Count :982307
Error Count :3
Historical Count :845555
Output Count : 95071
Run Started At : Tue Apr 10 09:25:32 EDT 2018
Run Ended At : Tue Apr 10 09:47:58 EDT 2018
Total Records Read: 95071
Total Records Added: 477
Total Records Skipped: 94547
Total Records w/error: 47

Output format should be below format and send email


Can someone please give me a script that allows me to robocopy a lot of directories from a source to a destination while referencing the directory names listed in a text file
The list will be in c:\scripts
Hello Everyone:)

I need a list of mailboxes on my Exchange server that includes:

- DisplayName
- Alias
- Primary SMPT-Address
- Premissions = This is actually the most important part of the evaluation I need

I should also be able to export this to CSV.

Any ideas how to do this in Powershell?
need some help here.. when I run the command, the message get truncated, it does not shows complete message in export csv file.. what am I missing here ?

Get-EventLog -LogName application  -after "4/8/18 3:00:00" -before "4/8/18 08:45:00"| ? {$_.eventid -match "9523" } | select -Property Source,time*,Machinename,message | export-csv C:\temp\NADB15.csv -notypeinformation
Hi Experts,

I need your help to create a shell script.

Below requirement lines may have repeated lines, please excuse me for that. It may be because I have tried to explain what ever first came in my mind.

Requirement is:

Search for data using parent ID from old.log log files which has sequence appended to it as suffix when it gets created.
Each old.log gets created with incremental sequence number after a perticular size has been reached like a log rotate.
I have to search through each old.log file for some data and capture it in Oracle database.

For example, lot of lines will have parent ID and same parent ID can also occur in next old.log sequenced file with an incremental suffix.
Once I searched for parent ID in a file and collected all it's data, I have to parse that data and insert in database.
Parsing meaning, I have to capture few field data like CHILDId, StartTime, FinishTime etc.

The challenge is, parent ID can be in next file too with it's relevant data so I have to search for parent ID in many files.
Data could be scattered all over log files, mostly once parent ID started the same parent ID would be in next log file and not in old log files. If parent ID started in old.log.12111 file then it can continue in next old.log.12112 log file.
old.log files be created every few minutes so script will have to remember which files it searched and skip them next time search.
I do not want to search through same log file next time, but I have to …
Duplicity Linux Backup to Azure

Hi All,

Can anyone help me with the error below please? When executing the following command, I receive the corresponding error.

duplicity --full-if-older-than 1M /srv/folder azure://container --archive-dir /var/lib/folder --volsize 2000 --tempdir /srv/tmp

Open in new window

Import of duplicity.backends.giobackend Failed: No module named gio
UnsupportedBackendScheme: scheme not supported in url: azure://container

Open in new window

Running on a updated Debian build with Azure CLI 2.0
I have no knowledge in power shell, but i need to use this script in another tool.

I have to unlock my local system when it is locked. I have to provide my credentials to unlock. This whole thing works under scheduling. We will schedule the file at particular time and lock the system. When the file runs at scheduled time, the system should be unlocked. Please help if there is any power shell script for this.

Thanks in advance
A folder having tons of duplicate *.msg files for example these 4 files (attachment1) now we want only one file to be kept in the folder after deletion of duplicate ones based on there LastWriteTime and length using powershell.
already tried this but it deleting all files in the folder which is obviously not required.
gci -Path D:\test\*.msg -file -recurse | Group-Object -Property TimeWritten | Where-Object { $_.Count -gt 1 } | select -ExpandProperty group | foreach {get-filehash -LiteralPath $_.fullname} | group -property TimeWritten | where { $_.count -gt 1 } | foreach { $ | select -skip 0 } | select -ExpandProperty path | foreach {Remove-Item -LiteralPath $_ -WhatIf}

Open in new window

Result.. (attachment2)
Thank you in advance..
Free Tool: Subnet Calculator
LVL 12
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

I would like a script to go through a directory of images and make folders and move images into that folder based on lines in a csv file.

For example:

The csv file would have column names like FolderName, Image1, Image 2, Image3, Image4

FolderName = 18-001
Image1 = 18-001.jpg
Image2 - 18-002.jpg
Image 3 = 18-003.jpg
Image 4 = personsname.jpg

So based on that wtihin the folder where the .csv file would be located and all of these images would be located I want to make a folder named "18-001" and then move Image1-4 into that folder.

With one catch.  I might sometimes have more than 4 images.  Each csv file might have different images.  So a "while" statement would be needed to read the .csv Image columns - they do all start with "Image"

current_usage=$( df -h | grep 'Filesystem' | awk {'print $5'} )

if [ ${current_usage%?} -ge ${max_usage%?} ]; then
    mailbody="Max usage exceeded. Your disk usage is at ${current_usage}."
    echo "Sending mail..."
    echo ${mailbody} | mail -s "Disk alert!" ""
elif [ ${current_usage%?} -lt ${max_usage%?} ]; then
    echo "No problems. Disk usage at ${current_usage}." > /dev/null

Getting integer expression expected error at line-4:
Hi Experts,

I am trying to create a shell script to mail me for errors from log.
If same error is coming again for some reason I do not want to send that again, just once.
I have already script in place to get all those errors in a text file, I am thinking of using that text for to mail me.

If possible:

If there are many errors at once in 5 minutes, I would like to send them as single email than sending them all separately.

Need your help and advise.

Thanks in Advance!
Looking for Bash code to create csv file and add data into. I

1.) check to see if the file exist
2.) create file if does not exist.
3.) place code in the error handling to add data about the error from the current jobs that just ran.
good morning,
I found this script on one of posting here and it was very helpful. I would like with the helps to modifying adding few output. I not getting it correctly.

I would like to add:
1) which executable program is using high CPU usage ( and duration time )
2)  how long user login duration ?
3)  can I change the freespace title to "freespace of C drive"
4) attach and email the report
5) bonus but not require last reboot time
6) bonus but not require, html format and email


GC C:\Temp\list.txt | % {
$Comp = $_
If (Test-Connection $Comp -Quiet){
$Luser = (Get-WmiObject -class win32_process -Filter "Name='Explorer.exe'" -ComputerName $Comp | % {$_.GetOwner().User} | Sort-Object -Unique) -join ","
$Mem = GWMI -Class win32_operatingsystem -computername $COMP
      New-Object PSObject -Property @{
      Server = $Comp
      "CPU usage" = "$((GWMI -ComputerName $COMP win32_processor | Measure-Object -property LoadPercentage -Average).Average) %"
      "Memory usage" = "$("{0:N2}" -f ((($Mem.TotalVisibleMemorySize - $Mem.FreePhysicalMemory)*100)/ $Mem.TotalVisibleMemorySize)) %"
        "Total FreeSpace" = "$("{0:N2}" -f ((Get-WmiObject -Class win32_Volume -ComputerName $COMP -Filter "DriveLetter='C:'" | Measure-Object -property FreeSpace -Sum).Sum /1GB)) GB"
       "logged Users" = $Luser
  "" | Select @{N="Server";E={$Comp}},"CPU usage","Memory usage","Total …
I am running esxi 6.0

I am trying to edit the file: /etc/rc.local using vi to run a script,

But I got a warning prevent me from saving my modification said "operation not permitted"
I want to run this command in the script because the shared data is not mounting automatically at the startup:

[root@esxi6lab:~] esxcli storage nfs add -H <shared_server_ip> -s <drive_path_in_the_shared_server> -v <volume_name>
Hi there,

I'm trying to run a bash script remotely on an Oracle server, but when I do I get errors.  The script runs just fine locally.

Command from server1 to server2:
ssh oracle@ /home/oracle/
Error on server 1:
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory

Same Command on server2:
oracle@VMUSDevORA01 ~]$ ./

PL/SQL procedure successfully completed.

Contents of
sqlplus -L -s system/SysOra1234@cloud_dev @cleanonegeo

I'm assuming it's because the ORACLE_HOME variable hasn't been set since I'm running it remotely, but what is a workaround so that I can run this script remotely?  What should I include in the script to get it working?
Thanks to Rick_2CA -

I have been able to Modify this script to include: TotalDeleteditemSize and TotalDeleteditemCount

This outputs the below and works exactly how I want:


The part I am having trouble with, and where I would like a push in the right direction is how to obtain the ArchiveTotalDeleteditemSize & ArchiveTotalDeleteditemCount (The count and size of data that CAN be archived, same as what is output from "ArchiveItemsSizeBytes")

Below is the script, that I have manipulated to include the

TotalDeleteditemSize & TotalDeleteditemCount......

I have attempted to match what was already in the script, by copying the code, and changing the values (Via Powershell ISE), However, I just end up with nothing being returned or getting the identical results as the ArchiveItemsizebytes

Essentially I am after the Archivable size & Count for recoverable deleted items

Any assistance would be greatly appreciated!!!

If I have worded anything wrongly, or something does not make sense, please let me know, and I will be happy to clarify...

# Exchange 2010 Mailbox PreArchive Statistics
# Purpose:  Query mailboxes for mail older than X days in order …

today=`/bin/date -d yesterday +%Y%m%d`
#sleep 600

ftp -n -i abcd_servername <<!
user username Pswd@123
cd /home/abcd/
lcd /appl/aaa/logs/stats
mput total_$server.$today
mput number_$server.$today
Free Tool: Path Explorer
LVL 12
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

I have a mailbox with tons of folders ( over 50000 folders ) and the person put lot of special characters that we think it is causing the activesync problem keep reloading.

so I would like to know, is there a powershell script where I can identify the folder that have special characters and rename it ?
i have a code like this


echo "leaving the function "
exit $1 ## should call builtin function

if [ ${AUTORUN} = "Y" ]
echo "cannot AUTORUN"
exit 1      #should call user defined function
echo "can AUTORUN"

is it possible to do it ?
I need help creating a Script that will Check if the Uptime(Hours) is exided on Windows 10 Operating Systems. I am not that Scripting guy just a newbie in the Scripting world.The following will be the Parameters I would like to have:

Parameter 1 specifies after how many hours without rebooting the user is asked via a message box  to restart their computer themself or to shut down .

Parameter 2 specifies after how many hours without restarting will the script plan an automatic restart in 60min (with no prompt for cancelling)

The script must be controllable with at least two parameters
Thank You in Advance
Hello Team,

Require a shell/perl script with below steps.
1) When disk space reaches 75%, trigger a cron job and move the old .arc files to another location.
2) Clean up the files in a folder by keeping only 8 hours of data available and it should be run every 15 mins.

I had this question after viewing Script for testing ping and telnet.

How can i modify this script to test telnet and mutual auth only

Expected Output
Flow ID |       From               |             To                      |          Test           |         STATUS
1            |  |       |       Telnet            |             OK
1            |  |       |       Mutual Auth |             OK
Hi I have a  data like below format

Site	Variable	Units	Model	29/00Z	29/06Z	29/12Z
CQT	500mbHeight	dm	MASS	588.4	589 	588.9
CQT	500mbHeight	dm	NAM	589.4	589.5	588.2

Open in new window

How can i transpose as one below (like repeat first 4 columns for transpose of each row after 4th column
CQT	500mbHeight	dm	MASS	29/00Z	588.4
CQT	500mbHeight	dm	MASS	29/06Z	589
CQT	500mbHeight	dm	MASS	29/12Z	588.9
CQT	500mbHeight	dm	NAM	29/00Z	589.4
CQT	500mbHeight	dm	NAM	29/06Z	589.5
CQT	500mbHeight	dm	NAM	29/12Z	588.2
CQT	500mbHeight	dm	NAM	29/18Z	589.6

Open in new window


Shell Scripting





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.