Script(s) to Automate Tasks


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script(s) to Automate Tasks
# 1  
Old 05-20-2008
Script(s) to Automate Tasks

I know that this has a bad title, but I'm not sure how to sum it up well.

(And I'm new to Linux in general, so please excuse any incorrect terminology Smilie)

Anyway, I'm trying to create a script that gets whatever folder you're in, and then does a command with that directory as an argument. I guess that it would be easier to show you than explain.

I want it to do a pwd command, and then just get that last folder (ie /home/alberte/study would translate into just study) and then put that on the end of a system command.

Now, I figured that I would be able to do this properly in bash, so I started out with this:

Code:
#!/bin/bash

pwd | sed 's_/_\
_g'

I would then pass this into a text file, look at the top two lines, and if there was text in the second line, it would delete the first line (eventually removing everything except the last folder). But then I realized that you couldn't do this with sed (or at least, I don't think it can). Talking with a friend, he directed me to perl, seeing as it would be easy to do text parsing, so heeding his words, I checked out perl.

Well, now, I can get perl to easily return the last word that was passed into it (ie "script.pl this is a test" would just print out "test"). So I figured that I could just call the perl script from the bash, and then I would be set. So, these are my scripts right now:

Bash
Code:
#!/bin/bash

pwd | sed 's_/_\ _g' | exec "/home/cfmc/study/perl.pl"

exit 0

Perl
Code:
#!/usr/bin/perl

$a = $#ARGV;

print "$ARGV[$a]\n"

Well, that really doesn't work. It looks like the Perl script isn't seeing this as arguments, but rather something else.

If any of you could point me in the right direction (even tutorials that feature this would be great), it would be very much appreciated. I've been working on this off and on for a few weeks, and I'd just like to get this done. Thanks for any help that you give in advance.
# 2  
Old 05-20-2008
basename `pwd`
# 3  
Old 05-21-2008
Thanks

Alright, I didn't know that there was an easy way to get the folder that you're in, and not the entire path. Thanks a lot for the help. I appreciate it.

Here's my final script.

Code:
#!/bin/bash

x=$(basename `pwd`)

mentor $x.qpx -test

exit 0

Thanks again!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script parallel tasks and command to wait untill complete?

Hello, im having bash script with while *** command1 && command2 && command3 && done i want to ask how i can prevent overloading server, by waiting untill all commands complete? any low resources intensive command like "wait" - i dont know if exist? (2 Replies)
Discussion started by: postcd
2 Replies

2. Homework & Coursework Questions

Shell Script to read a tab delimited file and perform simple tasks

1. The problem statement, all variables and given/known data: Hello! I need help with this problem bash shell scripting that basically just reads the data in a tab delimited file and does the following below 1. Read in the data file Survey.txt and assign the column values to variables of... (6 Replies)
Discussion started by: jsmith6932
6 Replies

3. Shell Programming and Scripting

Schedule tasks in shell script

shell=ksh, How could I schedule tasks in shell script INSTEAD OF using the crontab -e functionality? For example, I want a script to print "Hello World" every 10 seconds (i.e., INTERVAL = 10s) until external termination signal is triggered. Thanks, (2 Replies)
Discussion started by: isaacniu
2 Replies

4. Shell Programming and Scripting

Linking two tasks in a script

Hi, I have a question. I have a file that I need to do two things to. The first thing I need to do is turn a file with lines before and after a line with the term "Acceptance" into only the "Acceptance" line and every line thereafter. I am using this: grep -A1000000 "Acceptance" Brown_DL... (2 Replies)
Discussion started by: mikey11415
2 Replies

5. Windows & DOS: Issues & Discussions

automate the script

Dear all, I I want to login to my Linux machine using putty and then run some script from Windows machine.we can do it after loging it and then execute the script by typing it in putty command line screen. but I want to automate it.So whenever I will fire this script,it will do the following... (4 Replies)
Discussion started by: smartgupta
4 Replies

6. Shell Programming and Scripting

Automate remote script

Hi all, I need to execute a script on a remote machine that are connected to the network.The basic requirement is to write a script which will login in remote machine and then execute the other script automatically placed in remote machine.So that I need to execute the remote machine script... (3 Replies)
Discussion started by: smartgupta
3 Replies

7. Shell Programming and Scripting

Multiple Threads/Tasks to run parallely using the shell script

Scenario: I have two PCs (named as A & B) which would send some traps to my third PC (named as C). In PC C, I have to write a shell script such that it should accept the datas from both the PC-A & B parallely. So my question is, is it possible to have two different child threads/tasks... (2 Replies)
Discussion started by: nthiruvenkatam
2 Replies

8. Shell Programming and Scripting

How can I automate a script?

Hi All, Can I automate a script when some one trying to 'vi' (open) a file. For Example, I am having a file named 'SecuredShell.sh'. when a user types " vi SecuredShell.sh " in unix command prompt a script named secure.sh needs to be automated. Can this be possible. if Yes please guide... (2 Replies)
Discussion started by: little_wonder
2 Replies

9. Shell Programming and Scripting

Automate Script ***V. Urgent

Hi All, ./procdure.ksh which opens the below the menu, I want to build a script which will press 4 and run the Sector Data Automatically (instead of pressing option 4 manually) Is there any way for this, please let me know... 1) FX Rates MDU 9) Fidessa Cash... (7 Replies)
Discussion started by: niceboykunal123
7 Replies

10. Shell Programming and Scripting

here document to automate perl script that call script

I am trying to use a here document to automate testing a perl script however when the perl script hits a system(perl subscript.pl) call, input is no longer entered into this subscript. here is my script $ cat test.sh #ksh for testcase do program <<-EOF | tee -a funcscnlog.log y... (3 Replies)
Discussion started by: hogger84
3 Replies
Login or Register to Ask a Question