Difference between revisions of "WeBWorK shell - wwsh"

From WeBWorK_wiki
Jump to navigation Jump to search
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
  +
==''' Due to recent changes in Perl wwsh no longer gives you an interactive perl interface. Instead you call wwsh with a script as follows wwsh <course name> <script name>. '''==
  +
  +
 
=== SYNOPSIS ===
 
=== SYNOPSIS ===
   
Line 4: Line 8:
   
 
wwsh <u>COURSE ID</u>
 
wwsh <u>COURSE ID</u>
  +
  +
If this results in an error message such as <code>/usr/bin/perl -d: No such file or directory</code>, it means Perl is located in a different
  +
directory on your system. You can use the command <code>which perl</code> to find the location of Perl on your system and edit the first line of <code>wwsh</code> accordingly (<code>wwsh</code> is located in the directory <code>/opt/webwork/webwork2/bin/</code>). Or you can just run it with the command
  +
perl wwsh <u>COURSE ID</u>
   
 
From within the shell, one has direct access to the <tt>$db</tt> object for that course. Using the <tt>$db</tt> methods defined in WeBWorK::DB (<tt>webwork2/lib/WeBWorK/DB.pm</tt>) one can manipulate user records, permission records, and set and problem records.
 
From within the shell, one has direct access to the <tt>$db</tt> object for that course. Using the <tt>$db</tt> methods defined in WeBWorK::DB (<tt>webwork2/lib/WeBWorK/DB.pm</tt>) one can manipulate user records, permission records, and set and problem records.
Line 40: Line 48:
 
along with a number of other useful maintenance scripts.
 
along with a number of other useful maintenance scripts.
   
To start the WeBWorK shell, first export the location of your WeBWorK system code as <tt>WEBWORK_ROOT</t>. The standard installation instructions have the WeBWorK system code installed in <tt>/opt/webwork/webwork2</tt>. Using the bash shell the following command will export this location to <tt>WEBWORK_ROOT</tt>:
+
To start the WeBWorK shell, first export the location of your WeBWorK system code as <tt>WEBWORK_ROOT</tt>. The standard installation instructions have the WeBWorK system code installed in <tt>/opt/webwork/webwork2</tt>. Using the bash shell the following command will export this location to <tt>WEBWORK_ROOT</tt>:
   
 
export WEBWORK_ROOT=/opt/webwork/webwork2
 
export WEBWORK_ROOT=/opt/webwork/webwork2
Line 49: Line 57:
   
 
will start the WeBWorK shell for course COURSE_NAME.
 
will start the WeBWorK shell for course COURSE_NAME.
  +
  +
Once in the WeBWorK shell you can perform a variety of useful administrative tasks. For example, to add the <tt>admin</tt> user with password <tt>myPassword</tt>:
  +
  +
$db->addUser($db->newUser(user_id=>"admin", first_name=>"WeBWorK", last_name=>"Administrator",email_address=>"username\@school.edu", student_id=>"admin", status=>"C",section=>"", recitation=>"",comment=>"administrator"));
  +
$db->addPassword($db->newPassword(user_id=>"admin",password=>crypt("myPassword", "liquid09")));
  +
$db->addPermissionLevel($db->newPermissionLevel(user_id=>"admin",permission=>"10"));
  +
  +
For frequent tasks, you can put the appropriate sequence of commands in a text file and call the file from within wwsh to execute that sequence of commands. For example, if we put the commands above into a text file called <tt>addadmin</tt> in <tt>webwork2/bin/</tt>, then the command
  +
  +
source addadmin
  +
  +
run from within the wwsh for course COURSE_NAME would have the effect of adding the admin user to the course as above.
  +
  +
Note that <code>addUser</code> will fail if the <code>user_id</code> already exists as a user in the course. For this reason it is a good idea to pick a <code>user_id</code> which is unlikely to exist, e.g.
  +
$db->addUser($db->newUser(user_id=>"admin314159265", first_name=>"Temp", last_name=>"Admin",email_address=>"", student_id=>"admin314159265", status=>"C",section=>"", recitation=>"",comment=>"temp admin"));
  +
$db->addPassword($db->newPassword(user_id=>"admin314159265",password=>crypt("admin314159265", "dc")));
  +
$db->addPermissionLevel($db->newPermissionLevel(user_id=>"admin314159265",permission=>"10"));
  +
exit;
  +
  +
Alternatively you could use this code to alter the status of an existing user. Just make sure you know what you are doing-- you wouldn't want to lock someone out of the course this way:
  +
$db->putUser($db->newUser(user_id=>"admin", first_name=>"WeBWorK", last_name=>"Administrator",email_address=>"username\@school.edu", student_id=>"admin", status=>"C",section=>"", recitation=>"",comment=>"administrator"));
  +
$db->putPassword($db->newPassword(user_id=>"admin",password=>crypt("myPassword", "liquid09")));
  +
$db->putPermissionLevel($db->newPermissionLevel(user_id=>"admin",permission=>"10"));
  +
   
 
[[Category:Administrators]]
 
[[Category:Administrators]]

Latest revision as of 10:11, 30 August 2016

Due to recent changes in Perl wwsh no longer gives you an interactive perl interface. Instead you call wwsh with a script as follows wwsh <course name> <script name>.

SYNOPSIS

First, start the shell for a course with course id COURSE_ID:

wwsh COURSE ID

If this results in an error message such as /usr/bin/perl -d: No such file or directory, it means Perl is located in a different directory on your system. You can use the command which perl to find the location of Perl on your system and edit the first line of wwsh accordingly (wwsh is located in the directory /opt/webwork/webwork2/bin/). Or you can just run it with the command

perl wwsh COURSE ID

From within the shell, one has direct access to the $db object for that course. Using the $db methods defined in WeBWorK::DB (webwork2/lib/WeBWorK/DB.pm) one can manipulate user records, permission records, and set and problem records.

For example, one can get an array of all userids in the course:

my @userIDs = $db->listUsers();

One can create a new user record, define some properties of that user, and insert the record into the database:

my $new_user = $db->{user}->{record}->new();
$new_user->user_id("sammy");
$new_user->first_name("Sam");
$new_user->last_name("Hathaway");
$db->addUser($new_user);
$db->putUser($new_user);

One can retrieve an existing user record and then retrieve and manipulate the properties of the record and commit those changes back to the database:

$Dennis = $db->getUser("dennis");
print $Dennis -> status();
$Dennis->status("C");
$db->putUser->($Dennis);

The same can be done with permission level records:

$pl = $db -> getPermissionLevel("dennis");
$pl -> permission(10);
$db -> putPermissionLevel($pl);

One also has access to the $ce object for the course. See the documentation in WeBWorK::CourseEnvironment for specific access methods. The $ce object stores data defined in the global.conf file and any overrides set in the course.conf file of a course.

DESCRIPTION

The WeBWorK shell provides a specialized version of the Perl debugger intended for use by system administrators and developers. It can be used for course maintenance tasks and debugging. It can also be used to restore access to a course from the command line.

Inside the shell, the user has access to the $ce course environment object and $db database object for the WeBWorK course whose name is provided as the argument to wwsh.

The script for starting the shell is located in

webwork2/bin/

along with a number of other useful maintenance scripts.

To start the WeBWorK shell, first export the location of your WeBWorK system code as WEBWORK_ROOT. The standard installation instructions have the WeBWorK system code installed in /opt/webwork/webwork2. Using the bash shell the following command will export this location to WEBWORK_ROOT:

export WEBWORK_ROOT=/opt/webwork/webwork2

From within the webwork2/ directory, the command

$ bin/wwsh COURSE_NAME

will start the WeBWorK shell for course COURSE_NAME.

Once in the WeBWorK shell you can perform a variety of useful administrative tasks. For example, to add the admin user with password myPassword:

$db->addUser($db->newUser(user_id=>"admin", first_name=>"WeBWorK", last_name=>"Administrator",email_address=>"username\@school.edu", student_id=>"admin", status=>"C",section=>"", recitation=>"",comment=>"administrator"));
$db->addPassword($db->newPassword(user_id=>"admin",password=>crypt("myPassword", "liquid09")));
$db->addPermissionLevel($db->newPermissionLevel(user_id=>"admin",permission=>"10"));

For frequent tasks, you can put the appropriate sequence of commands in a text file and call the file from within wwsh to execute that sequence of commands. For example, if we put the commands above into a text file called addadmin in webwork2/bin/, then the command

source addadmin

run from within the wwsh for course COURSE_NAME would have the effect of adding the admin user to the course as above.

Note that addUser will fail if the user_id already exists as a user in the course. For this reason it is a good idea to pick a user_id which is unlikely to exist, e.g.

$db->addUser($db->newUser(user_id=>"admin314159265", first_name=>"Temp", last_name=>"Admin",email_address=>"", student_id=>"admin314159265", status=>"C",section=>"", recitation=>"",comment=>"temp admin"));
$db->addPassword($db->newPassword(user_id=>"admin314159265",password=>crypt("admin314159265", "dc")));
$db->addPermissionLevel($db->newPermissionLevel(user_id=>"admin314159265",permission=>"10"));
exit;

Alternatively you could use this code to alter the status of an existing user. Just make sure you know what you are doing-- you wouldn't want to lock someone out of the course this way:

$db->putUser($db->newUser(user_id=>"admin", first_name=>"WeBWorK", last_name=>"Administrator",email_address=>"username\@school.edu", student_id=>"admin", status=>"C",section=>"", recitation=>"",comment=>"administrator"));
$db->putPassword($db->newPassword(user_id=>"admin",password=>crypt("myPassword", "liquid09")));
$db->putPermissionLevel($db->newPermissionLevel(user_id=>"admin",permission=>"10"));