Check sys.indexes in every database where the name has -
IF @frag < 30.0
SET @command = N''ALTER INDEX ['' + @indexname + N''] ON ['' +@DBname+ N''].[''+ @schemaname + N''].['' + @objectname + N''] REORGANIZE'';
IF @frag >= 30.0
SET @command = N''ALTER INDEX ['' + @indexname + N''] ON ['' +@DBname+ N''].['' + @schemaname + N''].['' + @objectname + N''] REBUILD'';
IF @partitioncount > 1
SET @command = @command + N'' PARTITION='' + CAST(@partitionnum AS nvarchar(10));
-- PRINT N''Executed: '' + @command;
Added extra  around the db schema object in case anything else has special characters in the name.
Thanks for the update........
The above script is worked for me and job ran successfully in one server . I did same changes in another server (index optimization job),but the job was failing with the below error after changes also....
Executed as user: NT AUTHORITY\SYSTEM. Incorrect syntax near'('. [SQLSTATE 42000] (Error 102). The step failed.