As has already been said you need to create a console command. Create a directory called 'Command' in one of your bundles (the bundle needs to be registered in AppKernel.php. Then create a class in this directory, it will be automatically found by symfony when you run app/console.
Here is a quick example:
<?php
namespace Acme\FooBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\Command,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console\Input\InputInterface,
Symfony\Component\Console\Output\OutputInterface;
class BarCommand extends Command
{
protected function configure()
{
$this
->setName('foo:bar-cmd')
->setDescription('Test command')
->addOption('baz', null, InputOption::VALUE_NONE, 'Test option');
;
}
/**
* Execute the command
* The environment option is automatically handled.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Test command');
}
}
You can then run the command with:
$> app/console foo:bar-cmd
And pass in options like:
$> app/console foo:bar-cmd --baz