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

i'm trying to enable this "set-log Microsoft-Windows-PrintService/Operational /e:true" logging for each server and looking for how can I run for multiple server.

is it possible to do something like this to import. I know my line is not correct but looking for help here what I should correct to run multiple remote computer to enable this logging ?


----------------------------------------------------------------------
$servers = Import-csv "c:\Servers.txt"


foreeach($server in $servers){
     $cn=$server.Computername
     wevtutil set-log Microsoft-Windows-PrintService/Operational /e:true /r:"$cn"
}

----------------------------------------------------------------------
0
[Webinar] Lessons on Recovering from Petya
LVL 10
[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

I have an Access DB, in it I have an authentication form for users, I want to import data using a powershell script, but when the script opens the DB fails to import because the form does not enter the access data. My code is this and I could not make it work

$database = 'D:\db.accdb'
$Acc = New-Object –comObject Access.Application
$Acc.Visible = $false
$Acc.OpenCurrentDataBase($database)
$Acc.DoCmd.OpenForm('Form_Login_bd')
$AccForm = $Acc.Forms.item('Form_Login_bd')
$AccForm.Controls.Item("txt_login").value = "Test_Admin"
$AccForm.Controls.Item("txt_contrasena").value = "Test_Admin123"
.
.
.
script to import data
.
.
.

Any idea how to solve it
0
I have accidentally Rename more than 100 files in one Folder in Unix  like

File_Namee to   July_2016_FIle_name  Like all the file prefixed to same String "july_2016_"   How can I Reverse this action through Script?

Thank you Very Much.
0
Hi,
I have a requirement to fetch data in xls file using shell script, the requirement is simple whatever the table data that has to shown in xls file,

REGION_ID      REGION_NAME
1                      hello, you will be covering these many locations in this week
                        1.Perth
                        2.Sydney
                        3.Melbourne

I want to to show the same data in xls file but when I am generating it is not showing new line in xls cell instead the value is continued with the spaces which is incorrect.

wrong output - "hello, you will be covering these many locations in this week 1.Perth 2.Sydney 3.Melbourne"

for more please see the attached screenshot.

CREATE TABLE REGIONS
  ( REGION_ID NUMBER, REGION_NAME VARCHAR2(500)
  );
  
SET DEFINE OFF;
INSERT
INTO REGIONS
  (
    REGION_ID,
    REGION_NAME
  )
  VALUES
  (
    1,
    'hello, you will be covering these many locations in this week 
1.Perth 
2.Sydney 
3.Melbourne'
  );
INSERT
INTO REGIONS
  (
    REGION_ID,
    REGION_NAME
  )
  VALUES
  (
    2,
    'hello, you will be covering these many locations in this week 
1.NZ 
2.Tasmania 
3.NSW'
  );
INSERT
INTO REGIONS
  (
    REGION_ID,
    REGION_NAME
  )
  VALUES
  (
    3,
    'hello, you will be covering these many locations in this week 
1.Albany 
2.Busselton 
3.XYZloc'
  );
INSERT
INTO REGIONS
  (
    REGION_ID,
    REGION_NAME
  )
  VALUES
  (
    4,
    'hello, you will be covering these many locations in this 

Open in new window

0
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
0
I can run the following command and get a successful return code:

+ ssh ovmmgr01 '/opt/bmc/Patrol3/Linux-2-6-x86-64-nptl/bin/pconfig -version'
pconfig V10.7.00i Linux 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:14 EST 2007 x86_64 Build_20170217080901 Feb 17 2017
+ echo 0
0

If I try to add a grep, it fails.

+ ssh server1 '/opt/bmc/Patrol3/Linux-2-6-x86-64-nptl/bin/pconfig -version | grep V10'
pconfig V10.7.00i Linux 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:14 EST 2007 x86_64 Build_20170217080901 Feb 17 2017
+ echo 1
1

Any help would be greatly appreciated!

Thanks,
David
0
I need some fancy way to look in my file named "ocr-delete-records-pass-3.csv" in  that file there is a column B I need to match on my other file  "global-TXT-Records-ALL.csv" and spit out a new file called "text-remove.csv" I also need to preserve the format in the first file "ocr-delete-records-pass-3.csv" when the new output is produced.

In short I have a list of names in ocr-delete-records-pass-3.csv which I need it to look in  the master "global-TXT-Records-ALL.csv"  file for a match on the TXT record in column D from the "global-TXT-Records-ALL.csv" file.

If this can be done please advice

Thank you !
ocr-delete-records-pass-3.csv
global-TXT-Records-ALL.csv
0
I winder if anyone could help. Does anyone has any information on this?

A batch file required to run on a folder that will move into other folders based on file name and type.

What we have are scans coming off a locally attached scanner into one folder, need to sort from there where they will be moved to with the click of a cmd file

Example

Scans go to c:\scans

Format PDF

Sort will be filename, example car, truck, bike etc

Pre-existing folders in c:\Scans\Car, c:\Scans\truck, c:\Scans\bike

Any help would be appreciated

Thanks

John
0
Greeting Experts,

 I need help creating a script I can use to scan a list of websites and get the status code of each one ( i.e., 301, 302, etc.) and then put the output into a .csv file. Can somebody help me with this request
0
There are two input files: input1.txt is the actual file, input2.txt contains count of value in column 1 as per coulmn 2 from input1.txt.
need output which remove lines from input1.txt  (output.txt for reference)


input1.txt>>
abc[1.0],partition=xyz,deployedTime=20170302T2316388270600
abc[2.5],partition=xyz,deployedTime=20160713T2040505210500
bca[2.3],partition=yxz,deployedTime=20160713T2040505210500
bca[2.4],partition=yxz,deployedTime=20160813T2040505210500
bca[1.2],partition=yxz,deployedTime=20170302T2316388270600
bca[2.4],partition=xyz,deployedTime=20160813T2040505210500
bca[2.3],partition=xyz,deployedTime=20170713T2040505210500

input2.txt>>
2 abc xyz
3 bca yxz
2 bca xyz

output.txt>> should be in below format(have to remove latest version of column 1 as per coulmn 2 from input1.txt based on deployedTime)

abc[2.5],partition=xyz,deployedTime=20160713T2040505210500
bca[2.3],partition=yxz,deployedTime=20160713T2040505210500
bca[2.4],partition=yxz,deployedTime=20160813T2040505210500
bca[2.4],partition=xyz,deployedTime=20160813T2040505210500


Need help for generic command, that will work if input file contains n number of line.
0
Hire Technology Freelancers with Gigs
LVL 10
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

can i get any freelancers do powershell scripting
0
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.

Thanks,
Pra
0
I'm migrating to Office 365 from Exchange 2013 and I need a PS script to output either to csv or html that gives me shared mailboxes, calendars, or other users mailboxes  that all mailbox users in a specific OU in AD has access to.

I do not need the permissions or any other information other than the users in the specified OU and what they have access to.   Making it readable, for example instead of listing the user each time and the shared access, just list the user once and the shared objects; if not no big deal.

I've tried multiple scripts and variation and they have not given me the results I'm looking for. I'm hoping that an awesome scripting guru can make it happen.

Thank you in advance
0
Trying to create a quick script for the helpdesk to change calendar permissions on PowerShell through the O365 connector and i was wondering what do i need so that the console doesn't close after the below is run and they can continue with running some commands.

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Open in new window


I've seen that running it with the -NoExit switch could work but it's a little cumbersome, is there a better way from within the script?

Help as always is appreciated!
0
Greeting Experts,

I need help with a script I have been working on for past few days with some other friends. For some reason, the following script below gets the following error message. I have verified the import list has no spaces. Does anybody have any idea what I may be missing

Error Message:
A null key is not allowed in a hash literal.
    + CategoryInfo          : InvalidOperation: (System.Collections.Hashtable:Hashtable) [], Runti 
   meException
    + FullyQualifiedErrorId : InvalidNullKey
    + PSComputerName        : SawMillPro

Open in new window


Script:

$code={
    [Cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,Position=0)]$ComputerName
     )
     Process{
        $Dates=(New-Object -ComObject Microsoft.Update.AutoUpdate).Results
     }
     end{
        return new-object psobject -Property @{"Computer"=$ComputerName;"LastSearchDate"=$Dates.LastSearchSuccessDate;$LastInstallDate=$Dates.LastInstallationSuccessDate}
     }
}

$output=@()
$computer = Get-content "C:\list21.txt"
foreach($computers in $computer){
    $output+=Invoke-Command -ComputerName $computer -ScriptBlock $code -ArgumentList (@($computer))
}

$output | ConvertTo-Csv -NoTypeInformation | Out-File "C:\output.csv"

Open in new window

1
Greeting Experts,

I need help creating a PowerShell script that can scan a list of windows devices and find out when each windows machine received its last windows update. The script needs to be able to ask for Domain Admin Credentials, scan from a list of servers/workstations from an a.txt file, and then input the results of the scan into a .csv file with the server name/date&time of last time the device was updated. Can somebody help me with this task.... thanks for all of your help in advance?
0
Newbie bash_scripting here and trying to get someone else's script to work on my system, slightly altered.

I think I'm very close. The goal is to have Filebot move & rename media, then use ffmpeg to remux the file and insert comment, and finally rclone move. My guess right now is that remux_video.sh isn't being handed the "$1" filename correctly, or FileBot doesn't have the correct rights to launch /usr/bin/ffmpeg

I have been at this for a while and managed to get FileBot out of the Snap sandbox to get this far.

This is my edited script:

#!/bin/bash

#RCLONE_ACD_POINT="acdtest:media"
RCLONE_ME_POINT="/home/me/dir3/"
METADATA_COMMENT="TEST-COMMENT"
MOVIE_FORMAT="Movies/{n} ({y}) {vf}/{n} ({y}) [{vf}]{' CD'+pi}{'.'+lang}"
TV_FORMAT="TV Shows/{n}/{episode.special ? 'Special' : 'Season '+s.pad(2)}/{n} {episode.special ? 'S00E'+special.pad(2) :
s00e00} {vf}{'.'+lang}"
LOG_FILE="/home/me/log/Proc.log"
LOCK_FILE="/home/me/log/filebot.lock"
EXCLUDE_LIST="$1/Proc.txt"
EXEC_EACH="/usr/local/bin/remux_video.sh '{file}' '$METADATA_COMMENT'"

if mkdir "$LOCK_FILE"
then
        # remove directory when script finishes
        trap 'rm -rf "$LOCK_FILE"' 0

        if [ "$#" -ne 2 ]; then
                echo "filebot_process.sh <in_dir> <out_dir>"
                exit 1
        fi

        # get absolute paths
        IN="$(realpath $1)"
        

Open in new window

0
Hi Experts,

I am trying to remove the trailing characters like newline and CR before entering the value into a variable. The value in this variable will be entered into csv file

I did

a=`cat nohup.out|sed ':a;N;$!ba;s/\n//g'`

I am still getting \n or something when the data is put into the csv and the next variable is going to next line of the spreadhsheet.

Please let me know if there is a better way to avoid the next line
0
Hello,

I have a powershell script which essentially "works" but with one caveat.

This script queues all the mailboxes to export immediately (i.e. if my text file contains a list of 15 mailboxes then the script queues all 15 mailboxes to export immediately).

The problem I have found is that when the server is trying to export more than one mailbox concurrently, some of the mailbox exports fail.

So I would like a way to either:

1. Modify the script to only perform one export at a time or
2. Configure some setting in Exchange so that only one New-MailboxExportRequest is executed at a time (I've had a look at the settings for this cmdlet and cannot see an option to do this)

$Export = Get-Content C:\Mailboxes.txt
foreach ($i in ($Export)) {New-MailboxExportRequest -ContentFilter {(Received -lt '01/09/2017')} -BadItemLimit 200 -AcceptLargeDataLoss -Mailbox $i -Filepath "\\SERVER\Mail\$($i).pst" }

Open in new window


Thank you
0
Free Tool: Port Scanner
LVL 10
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.

Experts - I’d like to create a Linux/Unix read-only-root role for Auditors, InfoSec and Tech Ops, so they can examine a system without risk of breaking anything.
-      Using sudo or Centrify, we can grant the privileges to run some commands as root, e.g.  ls, cat, cksum and tail –f
-      I don’t want to allow root privileges for e.g. find, view or more/less, as they can be used to modify a system

Creating the role is easy; Making it easy to use is harder
-      `sudo cat filename |less` would work fine – the `cat` is run as root, the `less` as the unprivileged user. I can create a little script utility called something like “Auditors_less” to remove the need to remember the syntax.
-      `dzdo cat filename > ~/my_copy_of_filename` would work for the same reason, and give them a local copy to work with. Call it “Auditors_cp” or just “Acp”
(`dzdo` is the Centrify equivalent to sudo)

Replacing the functionality of `find` is the part I can’t figure out. The output of `find` gives the full path to a file. `find` also allows you to select on ownership, permissions etc., but that part could be replaced by
`dzdo ls -l |grep {pattern}`

So a scriptlet that takes a starting directory as input and produces output in the form
/path/to/file      : ls –l output of file
would be great, as grep can filter the output, e.g. for globally writeable files/directories

I’ve found similar questions on formatting `ls -lR` output on stackoverflow.com, but no usable answers – general opinion seems to be…
0
I have a question where i need to write a script which can search the following hives and delete any String value names which match my criteria.

i need to be able to search the entire HKU hive and HKLM

Example, i need to delete any key name that would be called "Malware A" and another one called "Malware B"
They tend to be listed under these directories below but if theres a way to search the entire registry that would be great

HKU\S-1-5-18\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN
HKU\S-1-5-21-1172670090-1033165640-4219323903-500\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN
HKLM\SOFTWARE\WOW6432NODE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN

I would prefer to be able to launch the script easily via CMD if possible open powershell via CMD
0
Hi Team,

We have folder called /opt/app
inside /opt/app we are running applications as elasticsearch and kibana in below respective folders.

/opt/app/elasticsearch
/opt/app/kibana

and processes are running in those folders as we.

Due to space issue. Now i want to mount to /opt/app folder without any data loss on the fly?
is it possible or not? if possible could you please suggest me what is the best way to proceed?
0
Have the text file below:

File output.txt

4-character_string_without_space:

1. A few lines of text without character ":"

4-character_string_without_space:

4-character_string_without_space:

4-character_string_without_space:

2. A few lines of text without character ":"
.....

Is there any way to remove the lines with "4-character_string_without_space: and the immediate blank line" if no text follows them? For example.

Original text file:
ABCD:

line1
line2
line3

ABDD:

DDBA:

line5
line6
 
....

Wanted output:
ABCD:

line1
line2
line3

DDBA:

line5
line6
 
....

ABDD: should be removed. Any gurus, is there any concise way to do that? Thanks a lot.
0
Hello All,

I wanted to run the below script

Get-WinEvent @{logname='application';starttime=[datetime]::today } -ComputerName "ABCDEFRR56d" | select timecreated,task, TaskDisplayName

Put the output to a excel file and send email to a distribution list.

Can any one help me with a script?
0
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            | 192.168.2.26:20  |    192.168.2.27:23       |       Telnet            |             OK
1            | 192.168.2.26:20  |    192.168.2.27:23       |       Mutual Auth |             OK
0

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.