← back to Sdcc Awards

cypressaward/scraper/setup-cron.sh

48 lines

#!/bin/bash

# Setup script for the hourly scraper

echo "Setting up Cypress Award Scraper..."

# Create .env file if it doesn't exist
if [ ! -f .env ]; then
    echo "Creating .env file..."
    echo "Please add your Supabase credentials to /root/cypressaward/scraper/.env"
    cp .env.example .env
fi

# Add to crontab for hourly execution
(crontab -l 2>/dev/null; echo "0 * * * * cd /root/cypressaward/scraper && /usr/bin/node supabase-scraper.js >> /var/log/cypressaward-scraper.log 2>&1") | crontab -

# Create log file
touch /var/log/cypressaward-scraper.log
chmod 666 /var/log/cypressaward-scraper.log

# Create systemd service for continuous running
cat > /etc/systemd/system/cypressaward-scraper.service << EOF
[Unit]
Description=Cypress Award Scraper
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/cypressaward/scraper
ExecStart=/usr/bin/node supabase-scraper.js
Restart=on-failure
RestartSec=10
StandardOutput=append:/var/log/cypressaward-scraper.log
StandardError=append:/var/log/cypressaward-scraper.log

[Install]
WantedBy=multi-user.target
EOF

echo "Setup complete!"
echo "To start the scraper service:"
echo "  systemctl daemon-reload"
echo "  systemctl enable cypressaward-scraper"
echo "  systemctl start cypressaward-scraper"
echo ""
echo "To check logs:"
echo "  tail -f /var/log/cypressaward-scraper.log"