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

We have a shared network folder with over 400,000 loose files and need to create a powershell script that will take those files and move them into folders in the same directory based on the last three characters of the filenames.

For example:

[\\servername\fileshare\file001.eps] -> [\\servername\fileshare\001\file001.eps]
[\\servername\fileshare\file002.eps] -> [\\servername\fileshare\002\file002.eps]
[\\servername\fileshare\file400001.eps] -> [\\servername\fileshare\400001\file400001.eps]
[\\servername\fileshare\file12345.eps] -> [\\servername\fileshare\345\file12345.eps]

I am newbie to powershell scripting and any assistence would be greatly appretiated.

Thanks,
0
HI,
Could you help with below scenario please

  1. On a Linux server
  2. I cd (change directory) to a directory app1 that I'm interested. E.g /home/oracle/app/app1
  3. this directory contains many sub directories with files
  4. I find all the files which are older than n days. E.g 20 days
  5. finally delete those file.

Up to this point things are working fine with below line
find ${directory} -type f -mtime +${NumberOfDays} -exec ls {} \;

Open in new window


now would like to delete all empty directories recursively inside /home/oracle/app/app1. Reason for finding empty directory...there could be some file created less then 20 days, so we don't want to accidentally delete the parent directory

could you help the best logic with sample script please

thanks in advance
0
How to decrypt a .pgp file using gpg command in red hat linux
0
I have 9 database servers need shell script for monitoring the disk space of few file system from all servers with email alert notification everyday and also another script with if disk space reaches 70%  with output in textfile. I don't have jump server and will have to use login credentials. Can you please help on this, need urgent help.
0
I would like to change Windows 10 desktop wallpaper using a batch script.
I have this code:
echo off

reg add "HKCU\Control Panel\Desktop" /v Wallpaper /f /t REG_SZ /d C:\Users\stins\Desktop\wallpaper1.bmp

reg add "HKCU\Control Panel\Desktop" /v WallpaperStyle /f /t REG_SZ /d 10

:: Make the changes effective immediately
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters

pause

Open in new window


sometimes it works, and sometimes it doesn't. Can someone suggest why this might be?

Thanks
1
When i execute this cURL command from my linux ubuntu CLI it executes as a GET instead of a POST request. What am i doing wrong here? I cant figure it out and its driving me insane!

Also this WORKS in postman, but when i run the exact cURL shell from postman i get a 400 from the API, the vendor is unable to specify what the issue is.

curl 
-v 
-POST
 -H 'Accept: */*'
 -H 'Accept-Encoding: gzip,deflate' 
-H 'Cache-Control: no-cache' 
-H 'Host: api.mapbox.com'
 -H 'content-type: multipart/form-data; boundary=——WebKitFormBoundary7MA4YWxkTrZu0gW'
 -form file=@/home/matt/test.geojson.ld 
--url 'https://api.mapbox.com/tilesets/v1/sources/achuhealth/mack-testing1?access_token=TOKEN'

Open in new window

0
Powershell Enter-PSSession no longer working. Recently I started using the PowerShell command Enter-PSSession to run several commands on some remote PCs.

My workstation runs Windows 10 Pro, and the target computers all run windows 7 Pro this is in a domain environment and I'm doing this with admin credentials. It worked at first, but recently I've started getting an error whenever I try to run the Enter-PSSession command as shown in the attached screenshot.
screenshot of errorother users with the same permissions as myself do not get this message and are able to use Enter-PSSession without trouble.

Is it possible to somehow reset my PowerShell preferences/settings back to default and remove any extra modules I may have installed that could have caused this?
0
I need to search 2 email mailboxes for search terms and specific dates how can i do this in power shell on the server
1
This is using a Solaris 11.  We have a monitoring server that shows that this Solaris server is have a few spikes on the memory performance for 4 consecutive weeks. This may not seems to be a big problem, however, my management need to have a clearer picture on this.

In view of this, my senior wants to implement a process monitoring to see differences in processes (daytime,user,pid,ppid,vsz,rss,pcpu,command) in /var/adm/perf which is running every 5 Minutes. The main objective is so as we can see which process causing the memory spikes at any time. I am not a shell script expert. Please suggest how to write a script that can accomplish the above task.

Thanks in advance.
0
Have a Ruby script the ssh into multiple servers. I am trying to modify it so that it would first attempt  to use password and then 2nd attempt use a key.
Have script do each by there self however I need to have one script that will try to use password first then key.

Below is my script:
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'

USER = 'USER'
PASS = 'password'
KEY = "~/.ssh/id_rsa"
hosts = ['host1',  'host2',] 

hosts.each do |host|
  Net::SSH.start(host, USER, :password => PASS, :keys => KEY,
                   :auth_methods => ["password", "keys"], :port => 22,
                   :timeout => 5,
                   :non_interactive => true ) do |ssh|
     result = ssh.exec!('hostname')
     puts result
     result = ssh.exec!('hostname -i')
     puts result
     result = ssh.exec!("echo \'*** ****\'")
     puts result
     puts result
   end
end

Open in new window

0
have a rename oneliner, but I cant seem to get it to work

my contents look like this:, but mass quantity

100.10.in-addr.arpa
11.5.10.in-addr.arpa

I need them all to have a .db at the end so

11.5.10.in-addr.arpa.db
100.10.in-addr.arpa.db

I have this string that I use to echo the change to screen to make sure I like it, but it does not work right, I cant seem to get it to add the.db


for i in `ls`; do newname=`echo $i | sed 's/.arpa//'`; echo mv $i $newname; done

Open in new window


Then i used this one to change it

for i in `ls`; do newname=`echo $i | sed 's/.arpa//'`; mv $i $newname; done

Open in new window


can someone please help me mod this please.
0
Need to change a value in a Package.json file that looks like this
package.json  
{
  "name": "Test",
  "version": "0.1.0",
  "repository": {
    "type": "git",
    "url": "git@github.com/test.git
  },
  "license": "UNLICENSED",
  "private": true,
  "devDependencies": {
    "chromedriver: "75"
}


Below code gives me chrome driver version 75
CHROME_VERSION=$(cat package.json \
  | grep chromedriver \
  | head -1 \
  | awk -F: '{ print $2 }' \
  | sed 's/[",]//g')

echo $CHROME_VERSION


Using a bash script - can anyone help me with how to update the value from 75 to 76?

I need to update the chrome driver version from 75 to 76. (Update the chrome driver version from 75 to 76)
0
Team,

I have the below script which will provide the Top 10 Recievers in Exchange 2016.

The issue is that, its taking very long time to provide the output. I did tried using the Invoke-Command , but no luck.

$msgs1 = Get-TransportServer | Get-MessageTrackingLog -resultsize unlimited -EventId "Receive" -Start(Get-Date).AddDays(-30)

$msgs1| Group-Object -Property Recipients | Select-Object name,count | sort count -desc | select -first 10 | ft -auto

Open in new window





Thanks
Krish
0
Hello Experts,

I have the below scripts which will provide the Top 10 senders information for last one month.

$msgs = Get-TransportServer | Get-MessageTrackingLog -resultsize unlimited -EventId "Send" -Start(Get-Date).AddDays(-30)
$msgs | Group-Object -Property Sender | Select-Object name,count | sort count -desc | select -first 10 | ft –auto

I would like to see if it possible to export the result as Bar chart in Excel. Below is the sample output and i have attached the screenshot of
output in Bar chart format.

Output :

Name      Count
xyz.com      3531
llccc.net      2206
abcc.co      1497
Kcic.com      1458
Llcnet.com      935




Thanks in Advance.

Krish
output-chart.JPG
0
i am trying to  using  if condition in while loop .but  loop is coming out after one iteration .
In file_names.txt contain text file names.after getting the names i am using ssh to connect another server and get the count of that file which is present that server.
this if condition is working fine when tried individually by hard coding the name.  

cat /usr/local/apps/jethro/devl/bin/file_names.txt|while read -r line;
do
	echo $line
	
	if [[ ${line} == DSI_BC_DIM* ]]; 
		then
			echo ${line}
			echo "DIM"
			b=`ssh  amzphxjethro05 'zcat /md1/dev-scripts/PTD-Jethro-Stage/DSI_BC/'"${line}"' | wc -l'`
			echo ${b}
			echo `expr "${b}" - 1`
	else 
			echo "working"
			echo ${line}
			b=`ssh  amzphxjethro05 'zcat /md1/dev-scripts/PTD-Jethro-Stage/DSI_BC/'"${line}"' | wc -l'`
			echo $b
	fi 
done

Open in new window

0
Hello Team,

Is it possible to create our own web page using PSWA(powershell web access)?

I am trying to create a powershell based web page which will be accessed by Managers for approval of Mailbox storage.

Thanks
Krish
0
I have bunch of IPs (like 5000) and I would like to find a reverse lookup.  I have a excel file where i have all the IPs. i want the script to read a file and do a reverse lookup and write the results in to a file.

what is the best way to put in a shell script .

please advise
0
I have about tons of servers, which includes different style of OS and version.

i have a landing server where i can ssh to all these servers with keys.

i need a script to run it remotely to all these servers and get the the following details. need space or tab in between so i can put it in excel

what is the best way to do using shell script with for loop to ssh to these machine. i can ssh to all servers using for loop and reading a tons of server name from a file.

hostname       OS      release       kernel version

i.e  
myhostname    Redhat  6.10   2.6.32-xxxx
0
i have a windows cmd script which has calls to other scripts
it runs tasks in consecutive order and is called from several config scripts
echo.starting upgrade on %oracle_sid% at %dt% >%mlog%

echo  hit a key to start 
pause

rem step 1
call:eecho "preparing source"
call %sdir%\prepare_source_12102.cmd 

rem step 2
call:eecho "creating standby 12102"
call %sdir%\create_standby.cmd

rem step 3
call:eecho "rollforward standby"
set activate=NO
call %sdir%\activate_standby.cmd

echo hit a key to ACTIVATE STANDBY 
pause 

rem step 4
call:eecho "activate standby"
set activate=YES
call %sdir%\activate_standby.cmd

echo hit a key to start upgrade to 12.1
pause 

rem step 5
call:eecho "upgrade to 12.1.0.2"
call %sdir%\upgrade_db_12102.cmd

rem step 6
call:eecho "post upgrade on 12.1.0.2"
call %sdir%\post_upgrade_db_12102.cmd
call:eecho "end of post upgrade on 12.1.0.2"

echo hit a key to upgrade to 12.2
pause

rem  step 7
call:eecho "preparing source for 12.2.0.1"
call %sdir%\prepare_source_12201.cmd 

rem step 8
call:eecho "upgrade database to 12.2.0.1"
call %sdir%\upgrade_db_12201.cmd 

rem step 9
call:eecho "post upgrade database to 12.2.0.1"
call %sdir%\post_upgrade_db_12201.cmd 
call:eecho "end of post upgrade database to 12.2.0.1"

echo hit a key to switch sids
pause

rem step 10
call:eecho "rename sids %oracle_sid% to %dest_sid%"
call %sdir%\switch_sid.cmd %dest_home_2% %oracle_sid% %dest_sid%
call:eecho "end of switch sids to "%dest_sid%"

goto exit

:eecho
title 

Open in new window

0
Hi All,

Really stuck in one place. I am new to plsql and shell scripting.

I have a shell script which is taking $1 parameter as JOB_ID while executing. means i am passing JOB_ID as $1 while running the script
like
sh test.ksh SW -- where SW is my JOB_ID

Now i need to create a new function inside an already existing package in oracle. This function should be called from script.
It should take $1 as input parameter and then i have a query which should go in function like-

select count(*) from job_tables where job_id=$1

Now the result can be either 0 or 1.

if result is 0 then i need to set a variable
JOB_NO in shell script as /home/users/abc

if result is 1 then i need to set
JOB_NO in shell script as /home/users/def

Please help me in solving this. How should i write and approach
0
CentOS 7 booting yad script on startup, tried making service script but when starting the service the status give me the following:

[patrol@ppt_ae33sf etc]$ systemctl status rc-local
  rc-local.service - /etc/rc.d/rc.local Compatibility
    Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
    Active: active (exited) since Thu 2019-05-30 12:21:27 EDT; 2h 19min ago
      Tasks: 0

May 30 12:21:26 ppt_ae33sf systemd[1]: Starting /etc/rc.d/rc.local Comaptibility...
May 30 12:21:27 ppt_ae33sf yad[5506]: cannot open display:
May 30 12:21:27 ppt_ae33sf sudo[5789]:                root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/nmtui
May 30 12:21:27 ppt_ae33sf sudo[5789]: pam_limits(sudo:session): invalid line '* -nofile 2048' - skipped
May 30 12:21:27 ppt_ae33sf sudo[5789]: pam_limits(sudo:session): invalid line '* -nofile 2048' - skipped
May 30 12:21:26 ppt_ae33sf rc.local[5494]: Your terminal lacks the ability to clear the screen or position the cursor.
May 30 12:21:27 ppt_ae33sf yad[5506]: cannot open display:
May 30 12:21:26 ppt_ae33sf systemd[1]: Started /etc/rc.d/rc.local Comaptibility.


It looks like Yad is trying to access a open display. is their a way to prevent this or a way to bypass the message and make this script start on startup? any help is greatly appreciated.
0
I have few OS commands which I need to run only through ADMINISTRATOR's CMD console
please advice how to call such batch script

example :TEST.BAT
how to make sure below  script called from admin cmd console
==

echo " Hello"

==
0
Hi Expert

good day

I trying to automate the process of manual generating of the patching report on the Redhat Linux distribution 7.3.

Need help, how to generate a python script or shell script to capture the following output to a csv files.

Errata ID,  Severity, Package Name Packages, before patching and after patching.

Many thanks
0
machineinfo.txtHi Experts,

In Bash unix shell I would like to search text in a file named “machineinfo.txt” (contains information about software installed on a computer) and search/filter on an install date = “” line between a specific date range from 20190401 to 20190513 and output the following lines in date order (most recent date at top of list) from the results of the search based on the date range (below is example output)

DisplayName = "Symantec Endpoint Protection
InstallLocation = "C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\14.2.1031.0100.105\"
DisplayVersion = "14.2.1031.0100"
InstallDate = "2019022

I’m not sure what command needs to be used, any help appreciated please? Attached is an example of the machineinfo.txt file. I’ve kept the file small with just a few software entries.

Thanksmachineinfo.txtmachineinfo.txt
0
Hello Team,

I am trying to setup a automatic Lync creation script. The script should check if the mailbox is created or not and then enable lync account.

Please let me know if there is any possiblities.

Thanks
Krish
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.