Shell Scripting

10K

Solutions

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

What VBA would I use that would download a file, but before doing so validate the file can be downloaded before attempting the pull. If possible please try to do this without using On ERROR. I'm trying to see if there is a solid way to check if a file can be downloaded without attempting the download first.

EXAMPLE
  • In the link above it would validate the file can be downloaded before attempting the download. If for any reason the file could not be downloaded a message box would appear stating "The file can not be pulled. The link may have changed."

EXTRA NOTES
  • I may have seen someone try to do this using Dos/Shell but couldn't get it to work at the time and don't remember where it is at.
0
Cloud Class® Course: Amazon Web Services - Basic
LVL 12
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

I wrote the following script to send me the names of new users added to AD in the last day. It works fine as long as there was only one user added.

If none were added,  I get this:
Send-MailMessage : Cannot validate argument on parameter 'Body'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

If multiple were added, I get this:
Send-MailMessage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Body'. Specified method is not supported.

If only one were added, I get an email that displays the same stuff you'd get if you just had this as your script:
$When = ((Get-Date).AddDays(-1)).Date
Get-ADUser -Filter {whenCreated -ge $When} -Properties whenCreated

(though all I really want is the Distinguished Name.

Could someone please help me update this script so that:
1) If no users were added, I just get an e-mail saying no new users in the body.
2) If one, or more users were added, I just get a list of their Distinguished Names in the body of the email.

Here's the script as it stands now:
$When = ((Get-Date).AddDays(-1)).Date
$body1 = Get-ADUser -Filter {whenCreated -ge $When} -Properties whenCreated
$Subject = "New Users Added in Last Day"


$AdminName = "me@me.com"
$Pass = Get-Content "\\mypath\cred.txt" | ConvertTo-SecureString
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AdminName, $Pass

Send-MailMessage -To …
0
How can I change the below via an
Exchange Management Shell script so
Test #2 updates the same C:\.... location
that Test #1 does when I force updates ?
---------------------------------------------------------------
Test #1
  4am automatic update location
  ** C:\Program Files\Microsoft\Exchange Server\V14\ExchangeOAB
---------------------------------------------------------------
Test #2
  Manual "ANYTIME" update location
  ** C:\Program Files\Microsoft\Exchange Server\V14\ClientAccess\OAB
1
Hi

I need a script in bash. Which will inform me about new files in the directory. I am new in scripting that is why cant build script properly.

I think i can do this via "if then"  ow with while.

Case like this.
Somedays in the month it will be uploaded some files to the directory. After adding new files, i want to script notify me that new files added successfully.
0
Dear experts,

I am a chartered accountant, CIMA and CFA.

I have a lot of experience in writing excel formulae (the entire credit goes to this forum, thank you experts).

I now want to pursue Financial Engineering.

I am learning C, C++ now. Once I become well versed with these two languages, I will move to learning Python.

Now from robustness, depth and FE requirement is Python better or MATLAB

I am not sure I have the bandwidth to complete/learn both.

Till date I have been learning C and I did not struggle to pick up the synatax or logic.

Kindly advice.
0
Hi Experts,
could you pls help me how to check if directory exist using asterisk "*" in bash "if condition".
Basically would like to check if directory exist like *Drop* or best solution please

Below is the sample script
cd /home/mobaxterm; mkdir tmp tmp1  Child_Drop1 Child_Drop2 Child_Drop3 Child_Drop4 Child_Drop5

base=/home/mobaxterm/tmp
base_dir="${base}/*Drop*"

ls -ltr "${base}/"*Drop*
cp -r  "${base}/"*Drop* ${base}/tmp1/

if [ -d "${base_dir}" ] ; then
  echo "drop exists"
  cp -r  "${base}/"*Drop* ${base}/tmp1/
else
  echo "drop do not exists"
fi

Open in new window


Thanks in advance
0
Hello Internet!

I have a few usb miners running on a raspberry pi.

this is what i'd like to achieve.

  1. automatically reboot pi every... say... 4 hours
[list=2]when pi starts up - start screen session and run cmd: sudo /home/pi/git/vthoang/cgminer/cgminer -o stratum+tcp://eu.stratum.slushpool.com:3333 -u zbw123.worker1 -p x --gekko-2pac-freq 150 [/list]

there are a few examples of this being done that i can find online but they all seem to assume a certain level of linux understanding and the truth is i know absolutely nothing about linux. i can follow instructions to the letter but thats about it! :-)

i have bought a book "for dummies" but i'm not finding the answers i need. If it were windows i'd wright a start.bat file i guess.

I downloaded a GUI for crontab which helps you manage scheduled tasks but of course it requires the appropriate files to exist already so that i may run....
0
Hello Experts,
we have a HTML code like :-
[root@200]# cat SHBODLogs.sh
#!/bin/bash

echo "</pre><br/><br/><u>MRComponents</u><br/><br/>"
echo "<table border=1 style='font-family:Calibri;font-size:11px'><tr><td><b>PID</b></td><td>" | awk '{print $0"<b>Application</b></td><td><b>Socket</b></td></tr>"}';
ps ax | awk '($3 ~ /[RS]/) && ($5 !~ /gnome-terminal/) && ($5 ~ /active/||/BroadCast/||/TServer/||/Broadcast/||/GOCONNECTION/||/POS/||/CM/||/CC/||/SMM/||/DoubleAgent/) && ($5 !~ /awk/) && ($5 !~ /sh/) {print "<tr><td>"$1"</td><td>"$5"</td><td>"$6"&nbsp;&nbsp;"$7"</td></tr>"}'
echo "</table><br/>";

HTML Output :-

HTML OutputHTML Output</pre><br/><br/><u>MRComponents</u><br/><br/>
<table border=1 style='font-family:Calibri;font-size:11px'><tr><td><b>PID</b></td><td><b>Application</b></td><td><b>Socket</b></td></tr>
<tr><td>27359</td><td>./CM</td><td>&nbsp;&nbsp;</td></tr>
<tr><td>27380</td><td>./SMM</td><td>&nbsp;&nbsp;</td></tr>
<tr><td>27392</td><td>./CC</td><td>&nbsp;&nbsp;</td></tr>
<tr><td>27484</td><td>./POS</td><td>&nbsp;&nbsp;</td></tr>
<tr><td>27525</td><td>./CONNECTION</td><td>&nbsp;&nbsp;</td></tr>
<tr><td>27550</td><td>./ACTIVE</td><td>1&nbsp;&nbsp;</td></tr>
<tr><td>27579</td><td>./ACTIVE</td><td>2&nbsp;&nbsp;</td></tr>
<tr><td>27659</td><td>./BroadCast</td><td>1&nbsp;&nbsp;</td></tr>
<tr><td>27696</td><td>./BroadCast</td><td>2&nbsp;&nbsp;</td></tr>
0
I have a challenge related to updating a RedHat server.

On this server several packages need NOT to be updated because of application dependencies.

For this reason when I update the server I do something along the line of:
1) Check if any available patch can be seen, if so save result to file: sudo yum check-update | awk '(NR >=4) {print $1;}' > /tmp/update_packages
2) Then I remove the "blacklisted" packages from /tmp/update_packages
3) Run yum update against the obtained file

While this procedure is ok what can happen if one of the update packages has one of the blacklisted ones as dependency is that also the blacklisted one will be updated, right?

Is there any other procedure that you can suggest for this kind of scenario?

Thanks for your time and help.
0
im looking for a script,

I have a folder, which needs to be copied 100+ servers, and in that a folder I have bat file needs to be executed and it will generate CSV file.
and again all the CSV files needs to be copied back to source.

All servers are in workgroup, not in a domain, uses the same password and user id.

environment windows 2008 r2 std and enterprise

Appreciate your help.. Thanks
0
Cloud Class® Course: C++ 11 Fundamentals
LVL 12
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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.
0
I have some questions about RHUI (I just have the acronym and I know that is related to Operating System updates):

  • What is RHUI?
  • How can I check with a BASH script if it is working?
  • How can I check with a BASH script if there are any available patches?

Thanks for your time and input.
0
Robocopy

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
0
Hi,

   We get some postgres db command files (Insert, Update, Create, Drop etc) with the DB commands in them on a location(\usr\DB Scripts) in our Linux environment.
We need to come up with a script, which when ran,
   -> creates a consolidated file, with the statements in each file, ended with a GO statement
   -> Move the individual files used in the above consolidated file, into an archive directory, with timestamp in the name.
   -> Leave any unused files in the original location (\usr\DB Scripts); These will be the files which may have been added just after the script was run
   -> Run another script which compiles the consolidated file, against the database.

Can someone kindly help with this? I'm fairly new to the linux world.
0
Currently writing a management menu interface for managing printers on our HP UX system.

Scripts are written in Korn Shell.

The following command
lpstat -pTERRYTST

Open in new window

returns the following:-

printer TERRYTST disabled since Apr 10 08:36 -
        new printer
        fence priority : 0

Open in new window


I need to be able to search the response for keywords to identify states.

So I need to fill a variable with 1 if the printer is disabled, another variable with 1 if its new.

No idea how to complete this in Korn Shell scripting as am very new to the language.

Help! :)
0
I am looking for some information online as to how to script using Windows PowerShell.  I am not a programmer and do not understand the syntax as to where all the symbols need to go in order to make scripts run correctly.  I need info that explains exactly how to do this as if you do not have programming experience.
0
I have a file with 10000 values. I need to search for these values on a Server folder and once found, need to copy the
file to another folder. The values to search for are in one column in a spreadsheet. Values attached. They are PDF's.

How can I accomplish this?
Book1.xlsx
0
I want to compare crontabs on 6 servers in centos 7 using shell script. Please help me. Thanks in advance
0
I'm trying to call mattermost "platform" application from a python script to create users & teams from a CSV file but i'm having an issue with the subprocess.call command which doesn't seems to recognize any parameter passed after --name.  I'm new to python so i won't be offended if you point me the obvious.

my CSV files got columns group, group_display, email, password.

with open("./accounts.csv", "rb") as wFile:
    os.chdir("/opt/mattermost/bin")
    wReader = csv.DictReader(wFile)
    for wLine in wReader:
        wCommand = []
        wCommand.append('./platform')
        wCommand.append('team')
        wCommand.append('create')
        wCommand.append('--name ' + wLine['group'])
        wCommand.append('--display_name \"' + wLine['group_display'] + '\"')
        wCommand.append('--private')
        print wCommand
        wRet = subprocess.call(wCommand)
        if (wRet == 0):
                print 'Imported ' + wLine['email']
        else:
                print 'Error importing ' + wLine['email']

Open in new window


i'm getting the error:

Error: unknown flag: --name mycustomername
Usage: platform team create [flags]


If i run the command from the cmd line with this command, it will pass:
./platform team create --name mycustomername --display_name "The Full Customer Name" --private

Any idea what i'm missing?
0
Cloud Class® Course: Microsoft Windows 7 Basic
LVL 12
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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"
0
How can I script:

Install all PKG in /foldername

Maybe write log somewhere too....

Thanks
0
Experts Could use some scripting assistance

function Get-ActivationStatus {
    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [string]$DNSHostName = $Env:COMPUTERNAME
    )
    process {
        try {
            $wpa = Get-WmiObject SoftwareLicensingProduct -ComputerName $DNSHostName `
                -Filter "ApplicationID = '55c92734-d682-4d71-983e-d6ec3f16059f'" `
                -Property LicenseStatus -ErrorAction Stop
        }
        catch {
            $status = New-Object ComponentModel.Win32Exception ($_.Exception.ErrorCode)
            $wpa = $null    
        }
        $out = New-Object psobject -Property @{
            ComputerName = $DNSHostName;
            Status       = [string]::Empty;
        }
        if ($wpa) {
            :outer foreach ($item in $wpa) {
                switch ($item.LicenseStatus) {
                    0 {$out.Status = "Unlicensed"}
                    1 {$out.Status = "Licensed"; break outer}
                    2 {$out.Status = "Out-Of-Box Grace Period"; break outer}
                    3 {$out.Status = "Out-Of-Tolerance Grace Period"; break outer}
                    4 {$out.Status = "Non-Genuine Grace Period"; break outer}
                    5 {$out.Status = "Notification"; break outer}
                    6 {$out.Status = "Extended Grace"; break outer}
                    default {$out.Status = "Unknown value"}
                }
            

Open in new window

0
I'd like to add a shortcut on my desktop that I can just double click to be able to launch "shell:startup" as per the suggestion in this Microsoft Article which says in part;

To add or remove an app from the Startup tab, press the Windows Logo Key  + R, type shell:startup, and then select OK. This opens the Startup folder.

I've tried creating a batch file to do the above, but it doesn't work for me... I just notice a DOS windows pop up for a second and then it disappears.

Can anyone show me how I can create an icon to be able to do this?

My system is a Windows 10 Professional install.

Many thanks...

Andrew
0
Please provide me with the Command line and Power Shell commands to clear the clipboard within Windows 10.
0
0

Shell Scripting

10K

Solutions

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.