Shell Scripting

9K

Solutions

10

Articles & Videos

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

I've never used Powershell to run scripts before so be gentle, this scripting stuff is very new to me :)

I just copied what I thought would be a very handy script from a Microsoft article that I saved as PatchScript.ps1, but when I try to run it in Powershell, I get the error:

File C:\1\patchscript.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:21
+ c:\1\patchscript.ps1 <<<<
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

I looked into signing and it seems like such a long winded process to go through just to run the occasional script I'm confident will be safe, so was wondering if there is an over-ride of some sort to run an occasional self created script?  

Or is there an easy way to temporarily disable the policy preventing the execution of scripts, and then re-enable that policy immediately afterwards to maintain the security that it provides?

Your help would be appreciated.
0
Free Tool: IP Lookup
LVL 9
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Hi Experts, how to pass (ignore) below line in regex. I'm  trying to achieve this in jenkins log parser plugin.

# Should pass
chmod: cannot access './config/temp_bkp_24072016/resources': Permission denied

# Should fail
chmod: cannot access './config/resources_bkp_24072016/resources': Permission denied

#regex rule. which I'm trying to handle above two scenario
warning /^(?!.*(temp_bkp))(.*Permission denied.*)$/

Open in new window



Thanks in advance
0
Hi experts,

I'm using grep inside a function by passing search string and log file to search for the string.
I call this function few times inside my bash script

This issue is, when no match found grep terminates/error out and it not processing further.

Sample
function printSummary ()
{
    local search_string="$1"
    local job_log="$2"

    grep  -irn -B 3 -A 3 "${search_string}" ${job_log} >> ${tmp_file}
}


printSummary 'unable to' /tmp/log #if string not found, it should continue to next two strings. but it error out here.
printSummary 'error at' /tmp/log
printSummary 'ORA-' /tmp/log

Open in new window



Thanks in advance.
0
hi All,

kindly help me to write a shell or python script to delete the weblogic files. The files are rotated but need to be deleted which are 30 days old. the find command doesn't delete the files because the number of files are huge.

below is the  .logs format of the weblogic servers
/wls1034/Middleware/user_projects/domains/Domain/servers/server3/logs/

server3.log00585
 server3.log00586
 server3.log00587
server3.log00588
server3.log00589
server3.log00590
server3.log00603
server3.log00604

server3.out00035
server3.out00034
server3.out00036
server3.out00037
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
The original filename is "test.txt".
The requirement is to append the date + Timestamp (format yyyymmdd_hhmmssmsi.txt) at the point the file "test.txt" is generated.


yyyy - year
mm - month
dd - day
ss - second
msi - milli-second
0
Hi,
I am very new to shell scripting and i want to do following
read a xml file to extract value of <not_matched> tag,
from each of <SQL_Analysis>,<Data_Analysis>,<Graph_Analysis>,<Excel_Analysis>,<Pdf_Analysis> tags and compare it against a some value and depending on the result say Pass or Fail.

Any help much appreciated.

XML file as below :
<Execution_Stats>
      <Total_Executions>1</Total_Executions>      
      <Total_Errors>0</Total_Errors>
      <SQL_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </SQL_Analysis>
      <Data_Analysis>
            <NOT_COMPARED>0</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>1</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Data_Analysis>
      <Graph_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Graph_Analysis>
      <Excel_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Excel_Analysis>
      <Pdf_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Pdf_Analysis>
</Execution_Stats>
0
Hi all,

I need to know if 5000 computers on a list .csv are UP?

Which command can i use?

I have this but is for only one computer.

Test-Connection -BufferSize 32 -Count 1 -ComputerName 192.168.0.41 -Quiet

Can you help me?
0
Hello,
I have in a shell script, a variable that uses xmllint like this:

Xpath_querry = $ (xmllint --shell $ {xmlfile} << EOF
    Setrootns << EOF
    Xpath count (// defaultns: $ {parse_tag /} / defaultns: $ {tag}))

This worked but now, I have an EOF error in the console at run time.
Would anyone know another way to rewrite this variable (that the variable is used later in the script)?
0
Currently have a script that has this in it and this portion works fine:

sshpass -p $pw ssh -q -t $user@$f sudo su -

$pw is the password the user types in
$user is the user of the script
$f is hostnames

What I would like it to do is
sshpass -p $pw ssh -q -t $user@$f sudo su - & cd /mnt/rsyslog/audits

But it doesn't seem to want to change directories.  

Do I need to have it call a script on the remote system for this to work?

Thanks
John

Update:  Attached is the generic version of my script
Line_Audit_Script.txt
0
Free Tool: Site Down Detector
LVL 9
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Hi ,
As part of my activity I collect few data on the Linux Server and would like to automate/updating a Microsoft word document in Linux.

I was thinking, we can have a word template and some kind of api to update (find/replace)

Could you give me some lead on how to achieve this please?
0
I am running inotifywait to listen new files on a directory. The directory has 600 permission and user is vmail.
and I am running inotifywait using root user.

this is the command I used

inotifywait -mq -e CREATE --format %w%f /var/vmail/xxx/unsubscribe/cur | while read FILE; do echo "$FILE"; done

Whenever I receive mail it's not identifying the new file.
When I manually create file using root user it's displaying the file name.

What I observed is when I receive mail, the permissions of the file is 600.
When I create the file using root the file permission is 622.

I tried to switch user from root to vmail and run the command but no use.

I am stuck here.

I need to unsubscribe the user whenever I receive new unsubscribe mail immediately.
0
Hi Experts
I need a batch file to change folder permissions and sub folders to the following
remove every users permissions except the administrator and the administrator only have the read only option
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
I have a issue where I want to have a shell script and change directories to remove a file.
For example;

1. Starting directory is /main/bin/scripts/ ( my shell script lives here ) removefile.sh
2. I want to change directories in the shell script and go to the level before main ( which is inputfiles/source/)
3. Need to locate a file and remove.

How can I do this? I've tried cd../../ but that doesn't work in the shell script.

Thanks
Jeff
0
I have a file with a character that translates into 272 when I do:
od -xc

The character looks like an A with a caret on top with a degree sign to the right. I am attaching an image of the character as well. I have tried sed, perl and tr and none of them are working.

For example:
sed -e 's/'$(echo "272")'/ /g' input_file > output_file

This does not work.

Any suggestions?
Image.jpg
0
script to ftp the txt files from windows to unix server automatically daily
0
How to stop and not kill a process
The .bat script bellow kills and don't stop my AlwaysUP.exe


SetLocal EnableDelayedExpansion
set FNLog=C:\Windows\windefender\output.txt
if exist "%FNLog%" (
  find "Finished" "%FNLog%"
  if !errorlevel! equ 0 taskkill /f /im AlwaysUp.exe /t
  ECHO del /q "%FNLog%"
)

Open in new window

0
in below code , it read all username from file users.txt with 1 word list word.txt .

now how can have multiple word file ? example word1.txt word2.txt ...

WORDS=word.txt
USERS=./users.txt

cat $USERS

while IFS= read -r USER
do
    echo "$USER `date`"
    time printf '1\n'$USER'\n'$WORDS'\n' | python Pulse.py 2>&1
    done < "$USERS"

Open in new window

0
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

I am creating a shell script to check if cron jobs are enabled/disabled and send a mail notification for the same (with job name).

#!/bin/sh

crontab -l > /app/file.txt
App_Home=/app
ctab='$APP_Home/file.txt'

while IFS= read -r value; do
entry=`$value | awk '{print $1}'`
echo $entry
if [[ $entry == "#" ]]
then
  echo " Entry $value is disabled "
elif [[ $entry == '#*' ]]
then
   echo " Entry $value is disabled "
else
   echo " Entry $value is enabled "
fi
done < $ctab

Open in new window


However, the above code is failing with the error message (#*: command not found).
0
Hi,

If any one can help please, I need a power shell command  list name, email address and mailbox size in MB from a particular domain.  My environment is Exchange 2010 with 250 accepted domains. Thanks for your help in advance.
 
Thanks
Abdul
0
every monday, we query the DB using sql statement with last week date. for example to query today 05/29 in db, i will use 2017-05-22 to 2017-05-26. Now i need a shell script to display & take last week dates automatically
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
Not quite sure if this is a good approach.  Looking at the last line of a file and then putting the 9 position into a variable.  The file is separated by commas.  It does not recognized the lastrec variable in the lastnum line.  


lastrec=$(awk 'END{print NR}' $f )  
lastnum=$(awk -F"," 'NR=="${lastrec}" {print $9}' $f )

thanks
bje
0
What is the easiest way to track and manage CIDR blocks/subnets?

I need to automate this processes when configuring/building a new environment to use a new CIDR block/subnets not already in use by other environments and add this information to a tracker?

So I want to have some sort of file that keeps track of all the CIDR blocks/subnets that are currently in use checks and gives me the next CIDR blocks available. How would I implement this logic?

  Client 1    10.172.0.0/22
            10.172.1.0/24 subnet
            10.172.2.0/24 subnet
            10.172.3.0/24 subnet
            10.172.4.0/24 subnet
client 2    10.173.0.0/22
client 3    10.174.0.0/22

            10.175.0.0/22  #Should give me this next available block

Open in new window

0

Shell Scripting

9K

Solutions

10

Articles & Videos

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.