title: How can i execute my django custom command with cron in a python script
body: <p>I have created a Django custom command. I would like to run this command at specific inervals of time (say for example every 5 minutes). How can i make this from my script or from terminal.</p>
  
  <p>My django custom command in periodic_tasks.py:</p>
  
  <p>`class Command(BaseCommand):
      help = 'Displays Data....'</p>
  
  <pre><code>def handle(self, *args, **options):
          hostip = '192.168.1.1'
          cmd = 'sudo nmap -sV -T4 -O -F --version-light -oX - '+hostip
          scandate = timezone.now()
          #scandate = datetime.datetime.now()
          self.addToLog('Detailed Scan',hostip,scandate,'Started')
          child = pexpect.spawn(cmd, timeout = 60)
          index = child.expect (['password:',pexpect.EOF, pexpect.TIMEOUT])
          child.sendline('abcdef')
          scandate = timezone.now()
          self.addToLog('Detailed Scan',hostip,scandate,'Finished')
          print 'before xml.....'
          with open('portscan.xml', 'w') as fObj:
              fObj.write(child.before)
              print 'in xml.....'
          print 'after xml.....'
          portscandata = self.parsexml()
          self.addToDB(portscandata,hostip)`
  </code></pre>
  
  <p>In my script I am trying to do this:</p>
  
  <p><code>test = subprocess.Popen(["*/5","*","*","*", "*", "/usr/local/bin/python2.6","periodic_tasks"], stdout=subprocess.PIPE)
  output = test.communicate()[0]</code></p>
  
  <p>I am trying to run this from terminal like this:</p>
  
  <p><code>*/5 * * * * root /usr/local/bin/python2.6 /home/sat034/WorkSpace/SAFEACCESS/NetworkInventory/manage.py periodic_tasks</code></p>
  
  <p>It is saying:
  bash: */5: No such file or directory</p>
  
  <p>Please suggest me if I am missing somewhere. Thanks in Advance</p>