How do I use the MOSS script? - perl

I am trying to run MOSS on my Mac OS X and I don't know what mistake I am making. I am not sure whether I am running the command properly or not. I downloaded this file as 'moss', gave this execution permissions and tried to run following:
./moss -l python -c "Assignment 1" -d assignment1/
I got the response as
Checking files . . .
OK
Which is wrong. The assignment1 directory has 4 python scripts. Two files are exactly similar, in one I have rearranged the code and in another I have changed the variable names.
I have sent the email for registration and I have not received any reply. So I am running the code with default user ID.
I also tried running it with sending each of those python files instead of working on a directory, still I get same response.
./moss -l python -c "Assignment 1" 1.py 2.py 3.py 4.py

Steps to get going with MOSS on your Mac:
Send an email at moss#moss.stanford.edu with the mail body containing the email you want to register.
Eg:
registeruser
mail "username#domain" <-- your email
You will then get a reply containing the script that you will need to save as “moss.pl”. Just make sure that your Mac has the “perl” folder within the “/usr/bin/“ folder. Else, change the path of the perl folder on the very first line of the script to be compatible to your machine.
Now set the execute permission using the command “chmod ug+x moss.pl”. This should allow you to send your queries to the Stanford server. If you were to not execute this command then you may be denied the permission to submit any queries.
Now submit the query to the server using the command similar to the following (note the command is not restricted to a single flag (i.e. -l)….refer the comments in the script for USAGE instructions):
“./moss.pl -l python file_1.py file_2.py”
The result on submitting a query such as above would be:
Checking files . . .
OK
Uploading file_1.py ...done.
Uploading file_2.py ...done.
Query submitted. Waiting for the server's response.
http://moss.stanford.edu/results/282371307.
Just review if you have followed all the steps above. I, then, don't see you having any issues getting the results. Maybe you were facing issues bcoz you were not registered initially.

Seems one should be registered to use it, instructions weren't clear on the site. I received the email finally with userid and ran the script, this time it worked.

I think you should resend the email in the format:
registeruser
mail youremail
In the reply email you will get your ID, replace it in the script and run the moss file again. You should get the link for the result.

Related

Get-Process cannot get the latest path

considering the following scenario:
I run the executable on the server
I renamed the executable files to a different one while the process is still running.
then use get-process -ID 50620 | Select * to list detail information of this specific process
the path shows previous data, while the actual executable file name was changed already...
how can I get the latest file name from the PowerShell?
Thanks!
why i am asking this:
we are using Terminal server for PDA applications, so once we updated the executable on server, we modify the pervious executable name to different one so when RDP users login system will automatically load the new executable.
just trying to get those sessions running pervious executable(who doesn`t logout and login again since the update) to send message so they know the executable was updated and they have so logout and login soon to load the latest code.

Perl script file run manually but not in crontab

I have a perlscript file was running fine in crontab but suddenly it stopped running without any modification.
cd /home/user/public_html/crons && ./script.pl 2>&1 >/dev/null
The top of the script file is #!/usr/bin/perl -X
The output expect from this script is changes in database
I have another script file with the same modification and still works fine
When I run the file in the browser it works fine and execute all lines without any problem
I tried full path /usr/bin/perl but it didn't work
I tried Perl at the beginning but it didn't work
I run the command from SSH using putty but nothing happened
I checked log file /var/log/cron but no errors at all
I created temporary log file cd /home/user/public_html/crons/script.pl> /tmp/temp.log 2>&1 to see the errors but the log is empty
Here is the solution:-
I found the issue, There is was a stuck process for the same cron file , so i killed this process and its fixed
You can find your file process like this
ps aux | grep 'your cron file here'
This is a really common antipattern people seem to tend toward with cron.
Cron sends you an email with the output of your script, if it generates any output. People often redirect output to /dev/null to prevent cron from sending the email. This is bad because now the output of your script is lost entirely. Even if the script has some built-in logging, it might generate errors before it gets the log file opened and those are lost. It also might crash in a way that doesn't get written to the logging mechanism.
At a bare minimum, you should just remove 2>&1 >/dev/null to start receiving the email. (and also, test your mail setup using a temporary cron job like 1 * * * * echo "Test" )
The next better solution is to change it to >> /var/log/myscript/current.log and then also set up something to rotate the log files (like logrotate) and also make sure to create that directory with permissions that the script user is allowed to write to it. By only redirecting STDOUT of the script, any errors or warnings it writes to STDERR cause you to get an email, and if there are no errors/warnings the output goes to the log file and no email gets sent.
Neither of those changes solve the root problem though, which is that when cron runs your script it does so with a different environment than you have on the command line. What you really want is a way to run the script with a consistent environment, and log it. The "ultimate solution" is to define your task in some kind of service manager, and then use cron to occasionally start it. For instance, you could use systemd and define a service that doesn't restart, then use systemctl start my_custom.service in your cron job. Now you can test independent of cron, and your tests will have the same exact environment, and be logged by the service manager. As extra bonuses, you are protected from accidentally running your script twice at once, and you get a clean way to stop a running cron job without the danger of stale pid files.
I don't particularly advocate systemd myself, but thankfully there are lots of alternatives:
Runit : http://smarden.org/runit/runsvdir.8.html
S6 : https://skarnet.org/software/s6/
Perp : http://b0llix.net/perp/site.cgi?page=perpd.8
(but installing and configuring a service manager is a bigger task than just using systemd if your distro is based on systemd) Each of these allows you to define a service that doesn't restart. Then you use a shell command to issue a "run once" directive to the supervisor, which runs the task as a child. Now you can easily launch the jobs yourself and see all the errors in the log, and then add that command to the crontab and know that it will run identically when cron starts it.
Back to your original problem, once you get some logging you are likely to discover it is a permission problem or a upgraded module in the system perl.

get user machines current working directory from perl cgi

i am trying to get the current working directory path using Perl
when i execute from ubuntu: $root#ubuntu:/var/test/geek# firefox http:/localhost/test.html, i get /var/cgi-bin as output in perl cgi page instead of /var/test/geek.
used perl code:
my $pwd=cwd();
bla bla
print "<h1> pwd </h1>";
above code gives path of test.pl not users working directory path
Edit: When i run the script alone from the terminal it works fine. for example:
$root#ubuntu:/var/test/geek# /var/cgi-bin/test.pl
i get /var/test/geek. but when i call the script in html page using submit button it gives path of perl script.
Each process has its own working directory that it inherits from its parent when it gets created.
cwd() returns the current process's working directory.
For a CGI script, the browser doesn't pass its working directory to the server as part of the request. To obtain that, you need to have code running on the client system that submits it. That might be an application that the user download, or possibly, but unlikely, some in-browser code, like Javascript / a Java applet (This info is likely hidden from in-browser code for security reasons though).
(The rest assumes Linux, it will likely differ on other operating systems)
The part below assumes that you are looking for the working directory of a user on the server:
In order to get a specific shell for a specific user's working directory, you would need to identify the PID for the shell and get the working directory from the /proc/<pid>/cwd symlink (To read these, the process must belong to the user running the code, or the code must run as root (Which is a bad idea for a CGI script)...). To get the PID of the shell, you likely need to start from the w command output, or its data source, /var/run/utmp. Sys::Utmp might be useful for this... You might then also need to retreive a whole lot of extra info to find all the processes that might have the working directory that you are looking for.
I think you are mixing the web server and the local user. The web server has a working directory when you run the script, and that is the one that cwd() returns.

Executing mail -s "testing" myemail#gmail.com just hangs. Why?

I'm debugging a problem with a script not emailing out.
When i execute the following outside of the script:
mail -s "testing" myemail#gmail.com
It just hangs. The terminal doesn't give me any feedback what it's doing or if it has finished. I can only enter a another command by CTRL + Cing it. Any ideas why? Sometimes it does work if I let it hang long enough (I will get an email about 2 - 4 minutes later).
I'm running CENTOS 5 something. I've just uninstalled sendmail and installed postfix to see if this fixes it and the same thing appears to be happening.
If you enter the above and hit it should take you to a blank line and wait for you to type the actual text of the message. Once you've completed entering the message, you enter a .<enter> (dot or period followed by enter key) as the first character on a line and (depending on the version), it will usually ask you to enter any CC: addresses. Hit again to proceed past that and it should then send the mail.
The above command doesn't actually send anything, the -s sets the subject, but unless you include a file it will simply wait for you to type something. If, on the other hand, you want it to just send something quickly you can have it pull in a file as the content of the message, e.g. mail -s "testing" myemail#gmail.com < some_text_file. This will read some_text_file into the body of the email and send it immediately.

How to send stderr in email shell script (ash)

I wrote a shell script that I use under ash, and I redirect stderr and stdout to a log file. I would like that log file to be emailed to me only if stderr is not empty.
I tried:
exec >mylog.log 2>&1
# Perform various find commands
if [TEST_IF_STDERR_NOT_EMPTY]; then
/usr/bin/mail -s "mylog" email#mydomain.com < mylog.log
fi
My question is twofold:
1- I get a -sh: /usr/bin/mail: not found error. It seems that the mail command doesn't exist under ash (or at least under my linux box, which is a Synology NAS), what would be the alternative? Worst case, perl is available, but I would prefer to use standard sh commands.
2- How to I test that stderr is not empty?
Thanks
How to check if file is empty in bash
As for the first question, in your code you are calling mail but lower in the post you are calling email. Check your code and make sure it is mail.
Use which mail to get the full path. Maybe it is not installed in /usr/bin/.
Use find to locate mail.
If you can go to another shell, run it and then execute which mail to get the full path of mail in case the path is set up in the alternative shells.