Hello,
Just a note I am SSH Secure Shell and a logic account and am currently doing basic UNIX Shell Scripts.
As part of an excercise I was told to "create an algorithm in pseudocode for the process of making a file executable. You would need to accept the filename as an argument, change the permissions on that file, output a message indicating the file is now executable, and do a long listing on that file to show the permissions"
My script consisted of the following -
#!/bin/bash
echo What is the name of the file you wish to make user executable
read filename
$bash chmod u+x $filename
echo The file $filename has now been made user executable
ls -la $filename
This worked fine, the next part of the excercise required me to - "add the following
A usage clause, to check the correct number of arguments are passed to the script
An if statement that checks that the file specified by the argument exists. If it doesn't exist, display a suitable message, otherwise, proceed with the chmod command. "
I changed my script to -
#!/bin/bash
echo What is the name of the file you wish to make user executable
read filename
# usage clause
if [ $# -ne 2 ]
then
echo "usage: $0 f1 f2" # follows typical manpage convention
# check file to move exists
elif [ ! -f $1 ]
then
echo "File $1 does not exist"
$bash chmod u+x $filename
echo The file $filename has now been made user executable
ls -la $filename
I then try to execute the script, it asks 'what is the name of the file you wish to make executable' and i type the name. However when i press enter it returns the error line 17: syntax error: unexpected end of file
Can someone please help me fix this, I have been at this all day and just want to get this excercise done. Sorry about the long winded post just wanted to make sure all the information was there to make it easy for people to pinpoint the problem. Cheers for any help and input, Benny
Hello,
thanks for the help with that I have now solved the problems with that script. However my final problem is with a script that i need to make to spell check a file and return the mispelt words and the line number of the mispelt words.
I have to implement -
myspell(file)
FOR each word in the mispelt list \\ use the spell command to create the list
line = find the line where the word occurs in the file \\ use grep with option n
DISPLAY the word
DISPLAY line
ENDFOR
END
My script currently looks like -
#!/bin/bash
echo What is the name of the file you wish to spell check?
read filename
word=`spell $filename` > mispelt.txt
line=`grep -n $word $filename` > mispelt.txt
echo $word
echo $line
exit
When I run it I get -
mary.txt
grep: can't open Marye
grep: can't open wamb
grep: can't open wittle
Delisious Marye wamb wittle
mary.txt:4: Delisious!
It finds the 4 words mispelt but will only display the line number for the word 'delisious' and can't get a line number for the other 3 words.
Your construct for searching for each word is incorrect.
Assuming you are using something like './myscript' to execute it then if you change the fisrt line from '#!/bin/bash' to '#!/bin/bash -x' and then run it you will cause the script to echo out each line it tries to execute before actually doing so. This is an invaluble debug tool for shell script writing.
Last edited by Unbeliever; 06-19-2006 at 04:13 AM..
So i ran the script and it came back -
+ echo What is the name of the file you wish to spell 'check?'
What is the name of the file you wish to spell check?
+ read filename
mary.txt
++ spell mary.txt
+ word=Delisious
Marye
wamb
wittle
++ grep -n -i Delisious Marye wamb wittle
grep: can't open Marye
grep: can't open wamb
grep: can't open wittle
+ line=
+ echo Delisious Marye wamb wittle
Delisious Marye wamb wittle
+ echo
+ exit
So i gather its finding all the words, but its trying to execute them all at once, is my grep command -n -i right and do i need to split them up?
Grep takes various options as argument (-n and -i in this case) then the next argument is the pattern to search for (Delisious) and the remainder is a list of file to search the pattern for.
So in this case you searched case independantly (-i) with line numbers (-n) for the pattern 'Delisious' in files called Marye, wamb and wittle.
You need to wrap the whole thing in some form of for loop. For example (not tested).
As an aside you have 2 lines in you original code:
In each case you are executing a command and catching the output in a variable and then redirecting output to a file. But of course all standard output has already been placed in the variable so the '> mispelt.txt' is redundant in both lines.
ah oh, thankyou for that. I tried to implement a for loop at first but couldn't really understand how to make it work, now I do. Thankyou for helping a confused newbie out with the this stuff, cheers benny
Hi all,
$ echo $SHELL
/bin/bash
Requirement - How to pass oracle sql script as argument to unix shell script?
$ ./output.sh users.sql
Below are the shell scripts and the oracle sql file in the same folder.
Shell Script
$ cat output.sh
#!/bin/bash
.... (7 Replies)
Hi team,
My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server.
I have completed the first part i.e From windows to using to unix server with the help of psftp.exe
code:
psftp user@host -pw password <... (1 Reply)
Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh.
Thanks in advance (2 Replies)
Hi,
Is it possible to ftp a huge zip file from windows to unix server using unix shell scripting?
If so what command i need to use.
thanks in advance. (1 Reply)
Hi,
I need help urgently for following issue. Pls help me to resolve this issue.
I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql)
I given... (6 Replies)
Can anybody help me out in sending parameters from sql*plus script to unix shell script without using flat files..
Initially in a shell script i will call sql*plus and after getting some value from some tables, i want that variable value in unix shell script. How can i do this?
Please tell me... (2 Replies)
I want to create an automated script which is called by another maually executed script.
The condition is that the no one should be able to manually execute the automated script.
The automated script can be on the same machine or it can be on a remote machine.
Can any one suggest a check in the... (1 Reply)
Hi ,
I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell.
So scenario is that
- I need to have one shell script which is ran as a part of crontab
- in this shell script I need to do a... (2 Replies)