Srikanth
Srikanth

Reputation: 63

How to handle SVN errors using shell script?

Dear All,
I am trying to achieve svn copy operation with the help of shell script. The problem am having is to handle svn errors like 403. Here goes a brief explanation about the problem,
My SVN structure looks like:

http://localhost/myproj/branches/dev/dev1
                                /testing/test1
                                /maintainance/m1

I am trying to write a shell script to achieve this task.
My Shell script expected behaviour:

Enter the Source url to be copied: http://localhost/myproj/branches/dev/dev1
Enter the new url name:http://localhost/myproj/branches/testing/test2

I don't want my script to show actual svn error to users, if user is not authorized in testing branch then svn shows 403 forbidden error, all I want is to tell the user that User is dont have access!! Not able to copy, contact administrator. Is there any possibility of redirecting the svn error to some variable and depending on the value of that variable will show the messages to user. I want to do it in shell script.. pls guide me.

Thanks in advance
Srikanth B

Upvotes: 0

Views: 2346

Answers (1)

me_and
me_and

Reputation: 15634

Redirect your outputs, using > and 2>. As a very simple example:

#!/bin/ksh
svn copy $1 $2 2>&1 | grep '403 forbidden'
if [[ $? -eq 0 ]]
then
  #The grep command was successful, i.e. '403 forbidden' was in the svn output
  echo No access.
  exit 1
else
  echo Complete
  exit 0
fi

This is very simple, and has a whole bunch of other problems, notably a complete avoidance of any other errors coming out of the svn command, but should give you an idea of how it could work.

Take a look at Wikibooks' page on Bourne Shell Scripting: Files and Streams for more information on how this works.

Upvotes: 3

Related Questions