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

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.
0
The 14th Annual Expert Award Winners
LVL 7
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

I recently updated a sync computer batch file from xcopy to robocopy.  This resolved some problems but I discovered that robocopy does not copy open files as xcopy did. Does anybody know of a copy routine that can run from a batch file that copies open files. The biggest problem is MS Word keeps files open in the background even after it is closed. It would be great if it has a copy version option (copy newer files to a new version number instead of overwriting the older file) and multi-thread capability. Free or low cost would also be good.

TIA
0
shell programming- sample file is below

I have 2 data files

data1

1,tom,tom@a.com
2,mike,mike@a.com

data2

1|05/05/2018/20000
2|06/05/2018/25000

Need help to merge the files and give me the desired output

1,05/05/05/2018,20000,tom, tom@a.com
2,06/05/05/2018,25000,mike, mike@a.com
0
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
       }
  }
  Else{
  "" | Select @{N="Server";E={$Comp}},"CPU usage","Memory usage","Total …
0
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>
0
Hi

Currently we are using shell script to connect to  mainframes and to get a file then we will execute macro to populate values into xls . Now instead of shell script  we want to use another approach . Please provide me possible solutions.

Thanks,
lokesh
0
need help with a Unix script.

1) Need to split a file that by fixed text and use part of the data to name the file.

Source file A

$$$$|DEF|ADDD
HDR|12345678|444|rhrhrh|hghghghg
LINE|33333|444444|ghththg
LINE|THHE|rrr|5555
LINE|TEHEHE|5555|urjurjr
HDR|234567890|444|rhrhrh|hghghghg
LINE|33333|444444|ghththg
LINE|THHE|rrr|5555
LINE|TEHEHE|5555|urjurjr

2) $$$$ starts new file
3) 2nd field in HDR is part of file name

Here is output

File B  name TESTTfile_12345678_20180130.txt

HDR|12345678|444|rhrhrh|hghghghg
LINE|33333|444444|ghththg
LINE|THHE|rrr|5555
LINE|TEHEHE|5555|urjurjr

File C  name TESTTfile_234567890_20180130.txt

HDR|234567890|444|rhrhrh|hghghghg
LINE|33333|444444|ghththg
LINE|THHE|rrr|5555
LINE|TEHEHE|5555|urjurjr

then original file saved to /archive

thanks!
0
Hi Experts,

I need to search multiple error keywords in Linux real time log files through shell script.
Below is something I tried and works on command line, it needs to be fine tuned or may be a different approach is needed.

Need your help.

grep -En "fatal|error|WARN|fail" /scripts/log.txt --color=auto > /scripts/log/errors_found.txt

mailx -s "Below are the errors found on host $(hostname)" -E email@email.com < /scripts/log/errors_found.txt

Thanks in Advance!

Sat
0
Dear Experts, how can schedule set of commands in Linux program?

For example: I want to schedule a program called A running at 12.00 AM everyday; but when that A program is running, a set of commands will be executed automatically.

Please suggest.
0
Hi Experts,

I trying to create a shell script.

I want to read words from one file and search them in another file. If any word not found then send email. If words found then nothing to do.

If multiple words not found then send that information as a single email rather than multiple emails for each word not found.

File1 contains process names and file2 contains current running processes.

Thanks in Advance!

Sat
0
Hire Technology Freelancers with Gigs
LVL 12
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.

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@10.41.22.69 /home/oracle/juletest2.sh
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 ~]$ ./juletest2.sh

PL/SQL procedure successfully completed.


Contents of juletest2.sh:
#!/bin/sh
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 juletest2.sh script to get it working?
0
Thanks to Rick_2CA - https://gallery.technet.microsoft.com/office/Mailbox-Pre-Archive-347f9162/view/Discussions

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

This outputs the below and works exactly how I want:

ItemsCount      
ArchiveItemsCount      
ItemsSizeBytes      
ArchiveItemsSizeBytes      
TotalDeletedItemSize            
DeletedItemCount


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 …
0
#!/bin/sh

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

ftp -n -i abcd_servername <<!
user username Pswd@123
bin
cd /home/abcd/
lcd /appl/aaa/logs/stats
mput total_$server.$today
mput number_$server.$today
bye
0
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 ?
0
i have a code like this

#!/bin/ksh

exit()
{
echo "leaving the function "
exit $1 ## should call builtin function
}

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


is it possible to do it ?
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
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 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
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

0
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.

Hi,

Please help me out for below problem...i want create the one shell script to upload file through lsftp and using below command but it is now working.

 lftp -oIdentityFile=/.ssh sftp://test:test@XX.XX.XX.XX -e "put tmp.txt.gpg; bye"
0
I am compressing files into one zip file and I am using the WSFTP script Editor/debugger and I want to rename the dest file to abc-yyyymmdd.zip. I am using the RENAME command as FirstFileName.txt abc-[YYYY][MM][DD].zip and that is what I get in the dest folder. I need the current date to be inserted.
0
Can someone help me out?  I need a shell script that can make an sftp connection with a password - installing the keys is not an option.  The scripts that I have (pasted below) throw an error saying that the command "expect" is not available.  Any help would be GREATLY appreciated.

#!/bin/sh

expect << 'EOS'
spawn sftp USERNAME@ip_address:/path/to/folder
expect "Password:"
send "PASSWORD\n"
expect "sftp>"
send "put file1\n"
expect "sftp>"
send "bye\n"
EOS
0
Hello Folks,

I have a script that came along with a project that someone was working on and requested that I continue to use because the initial person who set it up had it running in the environment. Anyways the purpose of the script to check to see if the "ttt.service" was been stopped and restart the service if this is true.
 
Now I've added the script, given below to a .bat file and created a Scheduled task to run the file every 5 minutes to check and restart the service it never runs. I then opened a command prompt and attempted to run the script from the prompt and yet it still didn't work.

Not really sure what im doing wrong and need some assistance..

@echo on
for /F "tokens=3 delims=: " %%H in ('sc query ttt.Service ^| findstr "STATE"') do (  if /I "%%H" NEQ "RUNNING" (      net start ttt.Service  ))
0
I currently login to the time from website using the following script.


browser = webdriver.Chrome('E:/Shared Folders/Users/runnerjp/chromedriver/chromedriver.exe')
browser.get("https://www.timeform.com/horse-racing/account/sign-in?returnUrl=%2Fhorse-racing%2F") 
time.sleep(3)
username = browser.find_element_by_id("EmailAddress")
password = browser.find_element_by_id("Password")
username.send_keys("usr")
password.send_keys("pass")
login_attempt = browser.find_element_by_xpath("//input[@type='submit']")
time.sleep(3)
login_attempt.submit()

Open in new window


it works but I find using Chrome web driver is hammering my CPU. Is there an alternative code I could use that does not mean I need to physically load the page to sign in?
0
Hi,
I'm running a script on Unity to run multiple applications at the same time with different settings the problem is every time I try to run the .sh file it gives me an error : Player data archive not found at 'location', using local filesystem. I looked up on google but no one seems to have the answer to this problem, do you have any idea why this is hapenning?

Thank you!

Log file attached.
global_index.js
index.js
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.