huck has asked for the wisdom of the Perl Monks concerning the following question:

I am reaching my wits end. I manage a small website for a friend. They want it on yahoo because it has been there and they have their mail addresses there. Recently something happened that caused updates and backups to stop working. The customer services group has been of no help so i have dug farther myself. I created the following perl program

#!/usr/bin/perl -w use strict; use warnings; use CGI; my $q = CGI->new; print $q->header('text/html'); print "<html><head><title>renamehuh Perl</title></head>\n<body>\n"; print '<h1>Why doesnt this work</h1>'."\n"; print '<pre>'."\n"; my $dir='/saveit/md5test'; use File::Basename; my $file=$dir.'/huh.saveit'; my $dpart=dirname ($file); my $fpart=basename($file); my $nback=5; if ($nback){ if (-e $dpart.'/bkup'.$nback.'-'.$fpart) { unlink $dpart.'/bkup' +.$nback.'-'.$fpart; } for (;$nback>1;$nback--){ my $nback1=$nback-1; my $thisfn=$dpart.'/bkup'.$nback1.'-'.$fpart; if (-e $thisfn) { myrename ($thisfn,$dpart.'/bkup'.$nback.'-'. +$fpart);} } if (-e $file) { myrename ($file,$dpart.'/bkup'.$nback.'-'.$fpart +); } } #nback open (my $out,'>',$file); my $time=time; print $out "hi $time\n"; close $out; use HTML::Entities qw/encode_entities/; print "\n\n<hr> perl program is $0 \n"; open (my $iam,'<',$0); while (my $line=<$iam>){ chomp $line; print encode_entities($line)."\n"; } exit; sub myrename{ my $thisfn=shift; my $newfn=shift; print " \n"; if (-f $thisfn) {print "$thisfn exists \n";} print "rename $thisfn,$newfn\n"; my $ok=rename $thisfn,$newfn; unless ($ok) {print "Cant rename $thisfn $newfn $!\n";} unless (-e $newfn) {print " .. $newfn doesnt exist \n";} return $ok; } #
When i run that program i get the following result.
/saveit/md5test/huh.saveit exists rename /saveit/md5test/huh.saveit,/saveit/md5test/bkup1-huh.saveit Cant rename /saveit/md5test/huh.saveit /saveit/md5test/bkup1-huh.savei +t No such file or directory .. /saveit/md5test/bkup1-huh.saveit doesnt exist
As you can see the my $ok=rename $thisfn,$newfn; is returning false and presenting "No such file or directory" in $!.

Customer service tried to tell me that it is because of .htaccess files. I find this hard to believe. Anyway for some reason yahoo is hiding dot-files from me via SFTP WINscp (also a FTP manager) and filezilla and their online file manager so i cannot remove them, and unlink/rename isnt working on them either

Does anyone have any ideas (besides yahoo being hosed) that could help me?

The base code is part of a backup procedure of mine that keeps prior copies in files named bkup1-huh.saveit, bkup2-huh.saveit, bkup3-huh.saveit ,bkup4-huh.saveit ,bkup5-huh.saveit. It works on 3 other linux boxes and about 4 windows boxes just fine, but not at yahoo.

If i run  unlink $file; on yahoo i get the same false result and error in $!

Edit: the permissions on the file are 664, i tried 777 but it made no difference, when i create the file via the web or FTP the uid/gid look the same as any other file on the website too

Replies are listed 'Best First'.
Re: problems with basic perl/unix commands on yahoo small business services
by hippo (Archbishop) on Aug 02, 2017 at 09:15 UTC
    Does anyone have any ideas (besides yahoo being hosed) that could help me?

    Can your CGI script

    • stat huh.saveit?
    • open huh.saveit?
    • read huh.saveit?
    • open bkup1-huh.saveit?
    • write to bkup1-huh.saveit??

    In that case you have a non-atomic copy operation which should at least get some backups in place while you batter Yahoo's customer support with your favourite LART.

    The real answer though (as no doubt you are already aware) is that if your friend is not paying you enough (or at all) then you must tell them either to host it somewhere sensible instead or find someone else to manage it for them.

      Yes i can do all those things. But the backups dont matter really. The only reason i put perl onto that box at all was to research the problem in the first place.

      The wordpress updates and backups began to fail. They were leaving a mess behind too. Customer service told me they didnt do wordpress support. I responded this wasnt a wordpress problem because it was working fine on other boxes.

      I knew i had to create a reproducible problem to get their attention. And id do that in perl at first. I knew unlink was failing, and i got it to fail in perl as well. Wanting a 5 mile view of the problem i wrote a little perl program to stat the entire tree. It saves it as a hash into a saveit file, and i can download that and read it on my local machine.

      Then i realized i wasnt getting the backups of the saveit files like i should have been. And i realized that rename was failing just like unlink was failing. I have a test program that shows that unlink fails much like that one but not as clean

      Pointing out these problem to Yahoo resulted in them saying i should repair my MySQL database and get rid of my .htaccess files, ones that their recommended plugins put there even.

      So i didnt get to the LART yet, not even a cane or switch. But i did ask to have the problem escalated. But yet i am still puzzled how a file can be created, read, statted, and rewrittem. but i cannot unlink or rename it. I was hoping someone here might have a clue

      And no, he is not paying me enough, he did give me a small bonus tho when he liked what i did to the page. Im not into flashy , nor is he. I didnt want it as busy as it is, but he did, so he got that. Its not much but if you like its located at http://jimstubblefieldfurniture.com. He keeps telling me he will send more pictures to put up but never does. I had been keeping the maintenance up on it as a favor. The last site was up for 4-5 years without any maintenance at all. If yahoo doesnt come thru, im sure he would be fine with not changing this one either. Hail, there are 3 times as many pictures as the last one had, and the phone number is current again.

      Thank you for your thoughts tho.

        "...he is not paying me enough, he did give me a small bonus tho when he liked what i did to the page...He keeps telling me he will send more pictures to put up but never does..."

        These are some of the major problems with this kind of projects. And their furniture looks much better than their website ;-)

        I guess it needs about one week to redesign their webpage a bit (static, yes), migrating the whole stuff to some virtual server which is available for ~ $10 monthly or so. Debian, nginx, fail2ban, ssh root access disabled and good is. For some good free and flexible html templates see Intensivstation. Regards, Karl

        «The Crux of the Biscuit is the Apostrophe»

        perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: problems with basic perl/unix commands on yahoo small business services
by Anonymous Monk on Aug 02, 2017 at 11:17 UTC
    Eew

    where is the error checking? %!